I'm writing a for loop to execute the forfiles command on both .xml and .psr files. Currently, if it finds one file type but not the other, it will display "ERROR: No files found with the specified search criteria", but I want the error to say which file type wasn't found. I have an if statement inside the for loop that's supposed to override the error, but it's not working. Here's the loop:
FOR %%G IN (.xml, .psr) DO (
FORFILES /P "%xmlDir%" /M *%%G /D -%days% /C "CMD /C DEL @FILE"
IF %ERRORLEVEL% NEQ 0 (
ECHO No matches found for %%G files older than %days% days
)
)
Edit: Thanks for the answers. My for loop now works as intended and ended up looking like this:
FOR %%G IN (.xml, .psr) DO (
FORFILES /P "%xmlDir%" /M *%%G /D -%days% /C "CMD /C DEL @FILE" >nul 2>nul
IF ERRORLEVEL 1 (
ECHO No %%G files %days% days old or older were found.
) ELSE (
ECHO %%G files as old as %days% days or older have been deleted.
)
)