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

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
goodywp
Posts: 265
Joined: 31 Jul 2017 09:57

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

#1 Post by goodywp » 12 Aug 2022 07:53

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.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

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

#2 Post by aGerman » 12 Aug 2022 09:28

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

goodywp
Posts: 265
Joined: 31 Jul 2017 09:57

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

#3 Post by goodywp » 22 Aug 2022 11:39

Yes it works thanks

Post Reply