我遇到嵌套if语法问题,我不断收到错误:
'ELSE' is not recognized as an internal or external command, operable program or batch file
这是功能:
:makejunction
set LOCALFOLDER=%~1
set QIFOLDER=%~2
pushd %LOCALFOLDER% 2>nul
IF errorlevel 1 (
IF EXIST %LOCALFOLDER% (
del "%LOCALFOLDER%"
)
)
ELSE
(
rmdir /S /Q "%LOCALFOLDER%"
)
mklink /J "%LOCALFOLDER%" "%QIFOLDER%"
谢谢!
答案 0 :(得分:1)
else
且括号必须在同一行:
:makejunction
set "LOCALFOLDER=%~1"
set "QIFOLDER=%~2"
pushd "%LOCALFOLDER%" 2>nul
IF errorlevel 1 (
IF EXIST "%LOCALFOLDER%" del "%LOCALFOLDER%"
) ELSE (
rmdir /S /Q "%LOCALFOLDER%"
)
mklink /J "%LOCALFOLDER%" "%QIFOLDER%"
答案 1 :(得分:0)
我认为你需要在if之后直接使用else,因此(
:
:makejunction
set LOCALFOLDER=%~1
set QIFOLDER=%~2
pushd %LOCALFOLDER% 2>nul
IF errorlevel 1 (
IF EXIST %LOCALFOLDER% (
del "%LOCALFOLDER%"
)
) ELSE (
rmdir /S /Q "%LOCALFOLDER%"
)
mklink /J "%LOCALFOLDER%" "%QIFOLDER%"
这应该可以正常工作
莫纳