0

我的嵌套 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%" 

谢谢!!

4

2 回答 2

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%" 
于 2013-10-14T22:37:03.813 回答
0

我认为你需要 else 直接在 if 之后,因此(

: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%" 

那应该可以正常工作

莫娜

于 2013-10-14T22:36:44.717 回答