3

I need to handle files older than a day. Thereforw I use this:

forfiles -m %%~nxf /C "cmd /c start /wait /MIN 7z.exe t %%f" /d +1

Now I'd like to check if the progress of 7z.exe succeeded. How can I get the errorlevel of the command inside the forefiles command? Is there any possibility?

I already tried following ways which did not work. errorlevel always returns 0, even if I use broken files, that should return an error (2).

forfiles -m %%~nxf /C "cmd /c start /wait /MIN 7z.exe t %%f && echo ok || echo delete %%f" /d +1

forfiles -m %%~nxf /C "cmd /c start /wait /MIN 7z.exe t %%f && if errorlevel 2 (DEL %%f)" /d +1
double-beep
  • 5,031
  • 17
  • 33
  • 41
mediii
  • 97
  • 2
  • 12

1 Answers1

1

Assuming 7z.exe does really deliver an ErrorLevel, I think that the conditional command separators query the ErrorLevel of cmd rather than of 7z.exe. The following should work:

forfiles /M "%%~nxf" /C "cmd /C 0x22start /WAIT /MIN 7z.exe t 0x22%%~f0x22 && echo ok || echo delete 0x22%%~f0x220x22" /D +1

Or you can do that also without start:

forfiles /M "%%~nxf" /C "cmd /C 0x227z.exe t 0x22%%~f0x22 && echo ok || echo delete 0x22%%~f0x220x22" /D +1

As you might have noticed, I also fixed some quote issues for the given paths.

aschipfl
  • 33,626
  • 12
  • 54
  • 99