How to assign fix drive letter in batch file? (SOLVED)
Moderator: DosItHelp
How to assign fix drive letter in batch file? (SOLVED)
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
Last edited by newbie on 17 Oct 2010 09:34, edited 1 time in total.
Re: How to assign fix drive letter in batch file?
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 %~d0
2nd) 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.
Regards
aGerman
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 %~d0
2nd) 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?
Thnx a lot, it did solve my prob.