批处理文件:搜索文本并继续处理错误

Batch file: Search for text and proceed on error

我试过写一个批处理文件,它会检查它自己的目录是否有其他批处理文件,并检查这些文件是否有特定的文本。如果找到文本,我希望程序跳到最后,否则将自己复制到找到的文件中。以下是我的尝试:

    rem windowsisajoke
    for %%f in (*.bat) do (set A=%%f)
    set FILE=%A%
    set CONTENT=windowsisajoke
    findstr /i "%CONTENT%" %FILE% >NUL
    if errorlevel 0 goto end
    copy %0 %A%
    :end

if errorlevel 0其实就是"if errorlevel is zero or greater"。 (我知道 - 非常直观...)

要么改变你的逻辑:

if errorlevel 1 copy %0 %A%

或使用

if %errorlevel%==0 goto :end