Page 1 of 1

how to get rid of this error even the scripts works as expected

Posted: 12 Aug 2022 07:53
by goodywp
Hi All,

I have below scripts to delete folders old than 15 days.

Code: Select all

forfiles /p "C:\CATA_AUTO\Report_Archive\Master\CHC" /s /D -15 /C "cmd /c IF @isdir == TRUE rd /S /Q @path"
It works and did the deletion but I also got these errors as below:

ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.

Is any way to get rid of these above errors?
Thanks

ERROR: The system cannot find the file specified.

Re: how to get rid of this error even the scripts works as expected

Posted: 12 Aug 2022 09:28
by aGerman
I guess the error comes from working recursively with both FORFILES and RD. Sooner or later it tries to delete a folder which is already deleted because its parent folder has been deleted before. So, you have two options:
1) Check whether @path still exists using IF EXIST before calling RD.
2) Just ignore the error messages using 2>NUL.

Steffen

Re: how to get rid of this error even the scripts works as expected

Posted: 22 Aug 2022 11:39
by goodywp
Yes it works thanks