DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Last post Author Topic: Script/batch file that copies two files from a drive(usb) to a location  (Read 68,286 times)

wolf.b

  • Member
  • Joined in 2007
  • **
  • Posts: 70
    • Programming School - Deluxe Bonus Medal
Re: Script/batch file that copies two files from a drive(usb) to a location
« Reply #25 on: February 03, 2008, 10:58 AM »
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:

Code
::TEST.BAT

echo %CD%

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

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

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

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

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



Quote
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.

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
Schön wär's, wenn's schön wär!

Original address: https://www.donationcoder.com/forum/index.php?topic=10846.0