如何在批处理文件中测试当前驱动器号?

问题描述:

我正在尝试编写一个批处理文件,该批处理文件将使用从中运行该批处理文件的驱动器号,并将其用作IF语句.例如,如果字母是M :,它将跳到标签:mSection.

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.

这有可能吗?

您可以使用%〜d0获取驱动器号. 像这样:

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

IF "%~d0"=="M:" CALL :mSection