命令的语法不正确 - for 循环中有多个 if 条件
syntax of the command is incorrect - multiple if conditions in for loop
这是我的代码:
for %%a in (%TESTS%) do (
IF not "%%a" == "tests/xxxx/yyyy/zzzz/test1" (
IF not "%%a" == "tests/qqqq/ssss/bbbb/test1892" (
and so on...
)
)
)
如果我有大约一百个 IF 条件,我就会收到这样的错误:
"syntax of the command is incorrect"
如果我注释掉几行(任何)IF 行,则错误不存在。
这段代码有什么问题?
你好。
很可能您超出了命令的 8192 个字符的限制 line/block。
所以您可以尝试以下操作:
for %%a in (%TESTS%) do (
call :SUB "%%~a"
)
exit /B
:SUB
if "%~1"=="tests/xxxx/yyyy/zzzz/test1" exit /B
if "%~1"=="tests/qqqq/ssss/bbbb/test1892" exit /B
rem and so on...
echo do your action(s) here (done only in NONE of the listed strings match)!
exit /B
if
语句是倒置的,因此不需要嵌套。
由于 if
行被转移到子例程 :SUB
,它们不再是过长 for
命令的一部分 line/block.
这是我的代码:
for %%a in (%TESTS%) do (
IF not "%%a" == "tests/xxxx/yyyy/zzzz/test1" (
IF not "%%a" == "tests/qqqq/ssss/bbbb/test1892" (
and so on...
)
)
)
如果我有大约一百个 IF 条件,我就会收到这样的错误: "syntax of the command is incorrect" 如果我注释掉几行(任何)IF 行,则错误不存在。
这段代码有什么问题?
你好。
很可能您超出了命令的 8192 个字符的限制 line/block。
所以您可以尝试以下操作:
for %%a in (%TESTS%) do (
call :SUB "%%~a"
)
exit /B
:SUB
if "%~1"=="tests/xxxx/yyyy/zzzz/test1" exit /B
if "%~1"=="tests/qqqq/ssss/bbbb/test1892" exit /B
rem and so on...
echo do your action(s) here (done only in NONE of the listed strings match)!
exit /B
if
语句是倒置的,因此不需要嵌套。
由于 if
行被转移到子例程 :SUB
,它们不再是过长 for
命令的一部分 line/block.