how to make a variable destination for COPY command
Hi guys, It seems that my title is very confusing. I dont know how to ask about it but let me explain. :) I created a batch file so that it will run automatically when I insert a usb drive. Here's the script cd \httrack rmdir tds.as /s/q httrack -r2 -i tds.as/kundeftp/tdstouch +*.pdf +mime:text/html copy tds.as\kundeftp\tdstouch\*.pdf e:\tds If you noticed on the 4th line, Im using the copy command. Now, I want the destination to be changed automatically when the USB drive is inserted to a computer. (the batch file is stored on the usb drive) Lets say, on the first computer, the usb drive is detected as E drive and on the second computer, it is detected as G drive. So, is there a way to make it as variable? Hope u guys understood my question... :) English is not my native language. I would appreciate if I can get a response right away. Thank you! Sincerely, Ed
April 26th, 2011 7:26am

Ed, A quick and dirty trick: Create on your USB drive a unique file (e.g. E:\TDS\Marker.mark) And use this as batchfile cd \httrack rmdir tds.as /s/q httrack -r2 -i tds.as/kundeftp/tdstouch +*.pdf +mime:text/html IF EXIST D:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf D:\tds ) IF EXIST E:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf E:\tds ) IF EXIST F:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf F:\tds ) IF EXIST G:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf G:\tds ) IF EXIST H:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf H:\tds ) IF EXIST I:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf I:\tds ) IF EXIST J:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf J:\tds ) IF EXIST K:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf K:\tds ) IF EXIST L:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf L:\tds ) IF EXIST M:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf M:\tds ) IF EXIST N:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf N:\tds ) IF EXIST O:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf O:\tds ) IF EXIST P:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf P:\tds ) IF EXIST Q:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf Q:\tds ) IF EXIST R:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf R:\tds ) IF EXIST S:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf S:\tds ) IF EXIST T:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf T:\tds ) IF EXIST U:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf U:\tds ) IF EXIST V:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf V:\tds ) IF EXIST W:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf W:\tds ) IF EXIST X:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf X:\tds ) IF EXIST Y:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf Y:\tds ) IF EXIST Z:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf Z:\tds ) You catch the drill :), i think this script can be easier but hey it works :). Kind Regards DFT IM me - TWiTTer: @DFTER
Free Windows Admin Tool Kit Click here and download it now
April 27th, 2011 4:57am

cd \httrack rmdir tds.as /s/q httrack -r2 -i tds.as/kundeftp/tdstouch +*.pdf +mime:text/html copy tds.as\kundeftp\tdstouch\*.pdf e:\tds and on the second computer, it is detected as G drive. So, is there a way to make it as variable? Hope u guys understood my question... :) English is not my native language. change the 4th line to copy tds.as\kundeftp\tdstouch\*.pdf %0\..\..\tds it's a really old (comes from DOS times) trick :) the idea is that %0 contains the full pathname of the batch file, so we leverage it to obtain the desired path; in short; let's say our batch file sits on the root of drive E: and is called cpfile.cmd now, %0 will assume the value "e:\cpfile.cmd" by adding the "\.." we'll tell the interpret to "strip" the extension and filename from %0 so we will obtain something like "e:\" now, let's just add a couple more dots to skip the folder name (which is \ in our case) and we'll be ready to address whatever absolute path on the same drive on which our batch resides HTH
April 27th, 2011 5:35am

Hi guys, To daf an obi wan, thank you soo much for your help.. I will try this script tomorrow.. been very busy this week at school.. I will get back to you soon.. Take care always guys..
Free Windows Admin Tool Kit Click here and download it now
April 28th, 2011 6:31am

hi daft, when you say marker.mark, ill just open a notepad and save it as marker.mark with no scripts on it? is that right? thanks, Ed
April 28th, 2011 6:37am

Ed, Yes, with no scripts or text in the file is ok. It is only to indentify your USB stick. If you look to the code IF EXIST L:\TDS\Marker.mark ( copy tds.as\kundeftp\tdstouch\*.pdf L:\tds ) This checks if the file L:\TDS\Marker.mark exists and if the file exists He copies the file to L:\tds. But ObiWan's solution is mutch better and cleaner :) Kind Regards DFTIM me - TWiTTer: @DFTER
Free Windows Admin Tool Kit Click here and download it now
April 28th, 2011 6:49am

hi obiwan and daft, I was using ur script and it works perfectly brothers.. thank you soo much.. Now, I have a last question, I created a vbs script and it contains this, set fso=CreateObject("Scripting.FileSystemObject") set WshShell=CreateObject("WScript.Shell") usbdrive="E" batchfile="\httrack\copy.bat" do if drivechk(usbdrive)<>"" then exit do wscript.sleep 1000 loop WshShell.run "cmd /c " & batchfile function drivechk(d) on error resume next set chk=fso.getDrive(d) if err.number then err.clear:exit function drivechk=chk.path end function the 4th line contains the letter assigned on the USB drive, is it possible to use this usbdrive="%0" ? Thanks, Ed
April 28th, 2011 10:32am

Ed, This won't work because %0 is specific to the batch langauge. If you want to have the current dirve where your script is executed from you can use this. usbdrive=Left(replace(WScript.ScriptFullName,WScript.ScriptName,"")1) This will return E if you run your Vbs script from your E: drive. Kind Regards DFTIM me - TWiTTer: @DFTER
Free Windows Admin Tool Kit Click here and download it now
April 28th, 2011 10:47am

hi daft, i tried changing the script. but i got an error message when i run the scipt. it says compilation error.. here is the full script.. set fso=CreateObject("Scripting.FileSystemObject") set WshShell=CreateObject("WScript.Shell") usbdrive=Left(replace(WScript.ScriptFullName,WScript.ScriptName,"")1) batchfile="\httrack\copy.bat" do if drivechk(usbdrive)<>"" then exit do wscript.sleep 1000 loop WshShell.run "cmd /c " & batchfile function drivechk(d) on error resume next set chk=fso.getDrive(d) if err.number then err.clear:exit function drivechk=chk.path end function
April 28th, 2011 11:32am

the 4th line contains the letter assigned on the USB drive, is it possible to use this usbdrive="%0" ? No way, see, that "%0" is specific to the batch environment and won't be understood by the scripting engine; if you need to retrieve the full path for the current script in "vbs" you'd better have a spin with the following code to get a grip about its working Dim fso, fil Set fso = CreateObject("Scripting.FileSystemObject") Set fil = fso.GetFile(WScript.ScriptFullName) WScript.StdOut.WriteLine fil.ParentFolder WScript.StdOut.WriteLine fil.Path the code simply retrieves the full pathname of the running script and then uses the filesystemobject methods to retrieve the path alone; I think that you'll be able to figure out how to extract the drive from that, won't you :) As a note, if you need to write vbscript code, try picking this editor it will help you speeding up your code editing tasks... and will also allow you to debug your code and even to turn your vbscript into an exe ... yes, not kidding ... and even a 64 bits one if needed :) HTH
Free Windows Admin Tool Kit Click here and download it now
April 28th, 2011 11:56am

hi.. the script that i post here, i didnt make it.. i just did a research on that. I dont know how to write vbsscript.. this is my first time to do this kind of stuff.. The main reason why i created a vbs script because I want something will automatically happened when I insert the usb drive in to the computer. The vbs script will call the batch file from the httrack folder and will execute the commands. So, I was wondering if what will i do with the vbs script i posted. and Obiwan, I cant figure it out.. huhuhu sorry... ;(.. Obiwan, you posted a script, i really dont get what you mean with that.. this will be the last part of my project.. thank you.. Ed
April 28th, 2011 1:56pm

guys? i really need your help.. thanks..
Free Windows Admin Tool Kit Click here and download it now
May 1st, 2011 4:33pm

Hi guys, Any ideas on creating an autorun file in calling a batch file? Been reading some information on the net and all it says is cd rom. Hope to hear from your response soon.. take care.. Ed
May 2nd, 2011 6:00am

Obiwan, you posted a script, i really dont get what you mean with that.. this will be the last part of my project.. thank you.. Save that script as "sample.vbs" and run it from a cmd prompt using the command cscript sample.vbs it will show you how to obtain the same value as for "%0" :) then you'll have to do your homework by adding that code to whatever vbscript you're putting together as for running a batch from an "autorun.inf" you may try entering the following as the autorun command %COMSPEC% /c yourbatch.cmd as a note; windows 7 and vista have autorun disabled by default, so I think you'll have hard time trying to make your stuff run there
Free Windows Admin Tool Kit Click here and download it now
May 2nd, 2011 6:43am

hi obiwan, thanks for your response. Just read your message now. I was able to convert my batch file to an .exe file and it works perfectly. It would be easier now to have the exe file run in autorun.inf here is my script, for some reason, i dont see an option to run the exe file in the autoplay list.. can u help me with this? Im using windows xp sp3 [autorun] open=tdsapp.exe action=Run PStart Program icon=tdslogo.ico label=My Portable PC anything is missing with my code? thank you.. hoping to hear from you soon. you've been very helpful.. Ed
May 5th, 2011 6:12pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics