Windows批处理嵌套函数语法内部函数

时间:2013-10-14 22:07:49

标签: windows batch-file nested conditional-statements mklink

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

谢谢!

2 个答案:

答案 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%" 

这应该可以正常工作

莫纳