Page 1 of 1
How to assign fix drive letter in batch file? (SOLVED)
Posted: 16 Oct 2010 00:47
by newbie
Hello, I would like to know how to assign fix drive letter in batch file? For example, pendrive, it could be e:, f:, g:, etc.So i would like to assign with fix drive letter for the usb drive even its a different a pendrive it still read as the same drive letter, need help???tq
Re: How to assign fix drive letter in batch file?
Posted: 16 Oct 2010 07:17
by aGerman
To different things:
1st) If you have to work on your pen drive you don't need the drive letter. Use relative pathes. Eg.: instead of
F:\data\xyz.exe you could use
\data\xyz.exe as well.
If you have a batch file on your pen drive, you will find the drive letter in
%~d02nd) If you work on the local hard drive and you have to determine what drive letter your pen drive got on the current computer, then it is realy complicated.
You could place an emty file on your pen drive (eg. "find.me"). Now you could loop over the drive letters to find it.
Code: Select all
@echo off &setlocal
for %%a in (D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
if exist "%%a:\find.me" set "DriveLetter=%%a:"
)
echo %DriveLetter%
pause
Regards
aGerman
Re: How to assign fix drive letter in batch file?
Posted: 17 Oct 2010 09:33
by newbie
Thnx a lot, it did solve my prob.