I have 1 .cmd file that runs a few things.  It then will access a Folder and from within this folder run an .EXE.  This all works fine when I run this from c:\temp or anyplace where I "know" the path.  but I need to place all of this onto a USB drive.  And when the USB drive is plugged into any machine I don't know what Drive Letter will get assigned.    How do you code your .cmd file so it will always find the "folder" you want and .EXE within the folder, regardless of the drive letter?  

Answer Summary:
Within your cmd file, use the "%~dp0" command
Cancel
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Community Chosen Answer

3

Are you running the .cmd file from the USB drive? Have you tried using %~dp0?

Answered 09/11/2012 by: dugullett
Red Belt

  • I want to run it all from the USB drive. And no, I did not try %-dp0. I will google that.
Please log in to comment

Answers

1

You could have the script copy the executable to the C drive, and then run it from there.

Answered 09/11/2012 by: muebel
Tenth Degree Black Belt

Please log in to comment
1

The %~dp0 command should be inside your cmd file.

If the executable is located in the same folder as your cmd file, use it like this: %~dp0YourExecutable.exe

If the executable is located in a subfolder, use it like this: %~dp0subfolder\YourExecutable.exe

 

Answered 09/12/2012 by: andemats
Second Degree Black Belt

Please log in to comment
Answer this question or Comment on this question for clarity