Job abends when there is no files to deleted

September 11, 2017 at 05:54:31
Specs: Windows 7
Hi guys i wrote a batch script to delete files older than a week. Below is my command

Forfiles -s -m *.* -d -7 -c "cmd /c del /q @path" 2>&1 | find /v /i "ERROR: No files found with the specified search criteria."

Using this command i am able to suppress "ERROR: No files found with the specified search criteria" in my logs. But my job that runs this batch file gets abended when there is no files that is older than 7 days. Can you please help me with a solution. Thanks in advance.


See More: Job abends when there is no files to deleted

Reply ↓  Report •

#1
September 18, 2017 at 20:25:31
Not sure what you mean by "job abends." FORFILES will return an errorLevel of 1, and if your script doesn't change it, some task scheduler system might pick it up as an error. To be fair, FORFILES does consider it an error.

There's a number of ways you could solve this issue, but the easiest way in this instance would probably be to make a temp file and set its modified date to some time in the past. If you need to keep the software first party, calling PowerShell from your batch script would probably be the best bet.

powershell -command "(ni tmpDel -t file).LastWriteTime = [datetime]::Today.AddDays(-8)"

How To Ask Questions The Smart Way

message edited by Razor2.3


Reply ↓  Report •
Related Solutions


Ask Question