I'm trying to write a batch file that takes the drive letter the batch file is being run from, and uses it an an IF statement. If the letter is M: for example, it will jump to the label :mSection.
Is this even possible?
To open the BAT file in Notepad, right-click it and choose Show more options > Edit from the menu (or just Edit in some Windows versions). You might find it helpful to use more advanced text editors that support syntax highlighting when editing a BAT file.
/d -- This switch makes cd change both drive and directory at once. Without it you would have to do cd %~d0 & cd %~p0 . ( %~d0 Changs active drive, cd %~p0 change the directory). %~dp0 -- This can be dissected further into three parts: %0 -- This represents zeroth parameter of your batch script.
FOR /F processing of a command consists of reading the output from the command one line at a time and then breaking the line up into individual items of data or 'tokens'. The DO command is then executed with the parameter(s) set to the token(s) found.
You can use %~d0 to get the drive letter. Something like this:
IF "%~d0"=="M:" CALL :mSection
You can use
%~d0 to
get the drive letter...
It doesn't work whet the .bat is on different drive (somewhere in the PATH.)
I'd suggest:
echo %cd:0,2%
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With