【发布时间】:2009-10-01 21:35:21
【问题描述】:
我有一个批处理文件,它从一个文本文件中解析出一堆文件名并将它们连接成一个单一的强文件 - 之前讨论过 here。但是,如果文件在我通过某些命令(例如 VCS 检查)运行时抛出错误,我不希望字符串包含文件。这是我的尝试:
set FILE_LIST=
for /f %%x in (temp.txt) do (
:: perform a VCS test
accurev diff -b %%x
:: skip concatenation if error level is > 2
IF errorlevel 2 GOTO NEXT
:: perform the concatenation
set FILE_LIST=!FILE_LIST! %%x
:NEXT
:: print a message if here due to an error above
IF errorlevel 2 echo VCS problem with this file: %%x
)
问题是 - 一旦发现一个大于 2 的错误级别,脚本似乎会立即停止执行整个 for 循环。如果列表中有五个文件,而第三个文件有 VCS 问题 - 脚本只处理前两个。
【问题讨论】:
-
看起来每次迭代都没有重置错误级别。是否可以在循环结束时手动将其重置为 0?
-
mmyers:看来advice from the internets 永远不会手动设置errorlevel 变量。
-
啊 - 我看到超链接格式在 cmets 中不起作用。
标签: scripting batch-file errorlevel