Hi CharlieLor
You can avoid getting error code 1 by adding the IF
statement to your script. The IF
statement will check if there are any files that match the criteria and only execute the del
command if there are.
Here is the modified script:
Forfiles.exe -p C:\temp\LogFiles\ -m *.log -d -10 -c "IF EXIST @path (Cmd.exe /c del @path)"
The IF
statement will check if the file exists at the specified path. If the file exists, the del
command will be executed. If the file does not exist, the del
command will not be executed.
This will prevent Task Scheduler from reporting error code 1 if there are no files that match the criteria.
Here is a more detailed explanation of the IF
statement:
-
IF
is a keyword that is used to check a condition. -
EXIST
is a function that checks if a file exists. -
@path
is a variable that contains the path to the file. -
(Cmd.exe /c del @path)
is a command that deletes the file.
By combining these elements, the IF
statement checks if the file exists at the specified path. If the file exists, the del
command will be executed. If the file does not exist, the del
command will not be executed.