jeudi 1 juillet 2021

In batch, is it possible to run a fc and an if %errorlevel% right after each other in a single for loop?

Basically, I am trying to write a batch file that will run an FC for all files in a directory (and its sub directory) and then run a separate batch script if an anomaly is found. Basically, the code is something like this.

(Upperpart_removed)

:main

for /f "delims=" %%F in (
Sth
) do (
    fc "folder/path ... " & if %errorlevel% NEQ 0 "C:\Users\user\command.bat"

)

if %errorlevel% EQU 0 goto main

Now the code looks a bit off because I had to redact folder paths and stuff (company security policy), but essentially every other line except for that fc ~~~ part is working. I am trying to figure out a way to run a batch file only if the errorlevel changes, and if its 0 just loop fc again. My current code ends up showing a "File not found" error but theerrorlevel remains 0 so the batch file isn't triggered. Does anyone know how to do this?

Aucun commentaire:

Enregistrer un commentaire