I have a batch file which is on a usb key. I need to know the drive name the batch is in.
Example, if it\'s E:\\mybatch.bat it should find E:\\ same thing for F:\\, G:\\
Like others have said %~d0
There's no point in going over that again, but if you have stumbled into this thread then this will cd to the directory of the batch file.
@echo off
set "fullDir=C:\Program Files"
cd /d %fullDir% &rem changes to the full directory 'C:\Program Files'.
echo You're now cd' in the '%cd%' directory.
pause
Also if you want to run a batch file from another drive such as Z:
then this one will do that.
cd /d %~d0 &rem Changes to the current directory
echo You're now cd' in the '%cd%' directory. &rem This is now your full path of the batch file cd' into.
pause