ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Coding Snacks

Script/batch file that copies two files from a drive(usb) to a location

<< < (6/6)

wolf.b:
Hi Jim,

thanks for the hints. My response is quite likely much too late, but I wasn't around for a while.

I have tried the environment variable %CD% that you mentioned in a batch file like this:


--- ---::TEST.BAT

echo %CD%

The output this batch file creates when called from within the directory where it is stored is as expected:


--- ---C:\Users\Wolf\>test.bat
C:\Users\Wolf

and the output when called from from the root directory is this:


--- ---C:\>Users\Wolf\test.bat
C:\

I noticed that the variable is inconsistent in adding a trailing backslash as the the ending character.


CopyMyFiles.cmd is stored in C:\Scripts
At the command prompt, you change directories to F:\Data
From there you type in the command
       C:\Scripts\CopyMyFiles.cmd
The %CD% variable will contain the value F:\Data.

--- End quote ---

I agree with everything you say, but would you not get the same behaviour when omitting the %CD%\ from your suggested CopyMyFiles.cmd?

copy data.exe c:\windows\system32\data
copy pic.jpg C:\Documents and Settings\Administrator\Desktop

I might have misunderstood the original question, but it seems to me that the question was to find a way to refer to the directory where the batch file is located (USB device?), rather than storing the batch on the hard drive.


Friendly

Wolf

Navigation

[0] Message Index

[*] Previous page

Go to full version