我创建了标签:checkNetworkDrive
来测试条件:
:checkNetworkDrive
setlocal
if not exist %drive%\ (
echo The specified drive does not exist
exit /b 1
)
exit /b 0
现在,从2个呼叫到该标签的呼叫工作方式有所不同。调用 label1 可以正常工作,即打印存在/不存在,而来自 label2 的调用会退出整个脚本。是由于标签2中存在setlocal enableDelayedExpansion
吗?
set drive=...
call :checkNetworkDrive
if %errorlevel% == 1 (
echo "exists"
) else (
echo "not exist"
)
setlocal enableDelayedExpansion
set drive=...
call :checkNetworkDrive
if %errorlevel% == 1 (
echo "exists"
) else (
echo "not exist"
)