4958Views5Replies

Author Options:

How do I make a batch file that will open a file from a flash drive (i.e., with a changing drive letter)? Answered

I use PortableApps on my flash drive, and it displays an icon in the menu if there is an application in the PortableApps/whatever directory. Two programs that work off a flashdrive, though not optimized for portable use, are Inkscape and Eagle. Both programs, however, have numerous applications in their main directories, which all appear.

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 Replies

user
orksecurity (author)2010-01-21

Or write the batch file to search drive letters, in sequence, for a file which you know will only exist on that drive (such as the executable).

Select as Best AnswerUndo Best Answer

user
iBurn (author)2010-01-21

 SOMETHING I KNOW ABOUT!!! :D
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.


Select as Best AnswerUndo Best Answer

user
g-one (author)2010-01-21

You can use 2 opportunities.

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"

Select as Best AnswerUndo Best Answer

user
NachoMahma (author)2010-01-21

.  IIRC, START <filename.ext> (no drive letter, dir name, nor leading slash) will look in the current directory.

Select as Best AnswerUndo Best Answer

user
lemonie (author)2010-01-21

To complicated, too silly. Fix the drive letter on the flashdrive instead. Batch script is like BASIC - limited, and few people write it for anything serious.

L

Select as Best AnswerUndo Best Answer