How do I make a batch file that will open a file from a flash drive (i.e., with a changing drive letter)?
What I'm after is a batch file that I can compile to .exe that will open the main program applications. I know that I can just put START C:/directory/application.exe to open an application from a known location, but my flash drive might be anything from E: to L:, depending on where it's used. Is there a command or code that will open a file from the same drive that the batch file is in, regardless of the drive letter?
5
answers
|
Answer it!
|
Just don't include the drive letter, because if you're running it from the flash drive it should automatically have the drive letter as its root. Hence, if you were trying to open a file called [inkscape.exe] from your flash drive which we will assume is [F:\], and it was located in a folder called [portapps], you would just type the following;
start portapps\inkscape.exe
exit
TA DA! That should work. If not you could always use a shortcut, but whatever.
1st Use a relative path (without the drive letter):
start "" "\somewhere\app.exe"
2nd Use the absolute path (the drive letter of your batch path find in %~d0)
start "" "%~d0\somewhere\app.exe"
L
![]() |

































