views:

1985

answers:

1

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?

Thanks

+6  A: 

You can use %~d0 to get the drive letter. Something like this:

IF "%~d0"=="M:" CALL :mSection
Dave Cluderay
That did it. Thanks!
JimDel
This will use the drive letter where the batch resides, though. If you switch drives to, say, Z: and do a M:\blah.cmd then you'll still get "M:" in the batch. You can use the %cd% pseudo-variable to get the current working directory if that is what you intended (and your question sounds like you do). If you need the drive letter from there you can just compare %cd:~0,2% to "M:". Otherwise you can simply jump to the appropriate section by using goto %cd:~0,1%section if you want to easily expand your abtch later on for different drives.
Joey