/build/static/layout/Breadcrumb_cap_w.png

Running scripts from a from USB drive

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?  


0 Comments   [ + ] Show comments

Answers (3)

Answer Summary:
Within your cmd file, use the "%~dp0" command
Posted by: dugullett 12 years ago
Red Belt
3

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


Comments:
  • I want to run it all from the USB drive. And no, I did not try %-dp0. I will google that. - mhsl808 12 years ago
    • Make sure it's ~ not - - dugullett 12 years ago
Posted by: muebel 12 years ago
10th Degree Black Belt
1

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

Posted by: andemats 12 years ago
2nd Degree Black Belt
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

 

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ