Hi CharlieLor
another solution:
To avoid receiving an error code 1 when using the Forfiles command in your Task Scheduler script, you can add a conditional statement to handle the scenario where no files are found. Here's an example of how you can modify your script:
@echo offforfiles /p "C:\temp\LogFiles\" /m *.log /d -10 /c "Cmd.exe /c del @path"REM Check the error level and handle it accordinglyIF %errorlevel% NEQ 1 ( echo Files older than 10 days deleted successfully.) ELSE ( echo No files found older than 10 days. REM Perform any necessary actions or skip further steps.)
In this modified script, the IF %errorlevel% NEQ 1
statement checks if the error level returned by the forfiles
command is not equal to 1. If the error level is not 1, it means that files were found and deleted successfully. In this case, the script echoes a success message.
In this modified script, the IF %errorlevel% NEQ 1
statement checks if the error level returned by the forfiles
command is not equal to 1. If the error level is not 1, it means that files were found and deleted successfully. In this case, the script echoes a success message.
In this modified script, the IF %errorlevel% NEQ 1
statement checks if the error level returned by the forfiles
command is not equal to 1. If the error level is not 1, it means that files were found and deleted successfully. In this case, the script echoes a success message.
If the error level is equal to 1, it means that no files matching the criteria were found. The script echoes a message stating that no files were found and you can perform any necessary actions or skip further steps based on this condition.
By including this conditional statement, you can handle the case where no files are older than 10 days without the script reporting an error code 1.