Forfiles error

June 25, 2010 at 16:53:12
Specs: Windows XP
Hi All,
I have a script that deletes files in folder that are older than 1 year.

FORFILES /P D:Doc\ /M *.txt /D -366 /C "cmd /c del @path"

It works good, except when it does not find any files older than 1 year, it gives the following error:

ERROR: No files found with the specified search criteria.

is there any way i could ask to ignore this error

Thanks.


See More: Forfiles error

Report •


#1
June 25, 2010 at 17:06:44
you might try this:
FORFILES /P D:Doc\ /M *.txt /D -366 /C "cmd /c del @path" 2>nul
or you might need it like this:
FORFILES /P D:Doc\ /M *.txt /D -366 /C "cmd /c del @path 2>nul"



Report •

#2
June 25, 2010 at 17:32:33
Thanks nbrane,
But won't this suppress all the errors and not just "ERROR: No files found with the specified search criteria.".

Wanted to see if i can just ignore this one and not the rest


Report •

#3
June 25, 2010 at 17:37:13
ahh, maybe this then?
FORFILES /P D:Doc\ /M *.txt /D -366 /C "cmd /c del @path" | find /v /i "ERROR: No files found with the specified search criteria."

Report •

Related Solutions

#4
June 25, 2010 at 17:50:34
still getting the same error -
ERROR: No files found with the specified search criteria.

Report •

#5
June 25, 2010 at 17:51:57
what does the command actually do?

Report •

#6
June 25, 2010 at 18:07:57
it was supposed to send the command's output through the "find /v" filter. Find /v means "return all strings NOT equal to:
"ERROR: No files found with the specified search criteria."

but i wasn't thinking straight. I think you need a for-loop capture:
for /f "tokens=*" %%a in ('FORFILES /P D:Doc\ /M *.txt /D -366 /C "cmd /c del @path"') do echo %%a | find /v /i "ERROR: No files found with the specified search criteria."
:: ------
i have a strong suspicion that this won't work either however.
any reason you're using a second CMD process?
instead of:
FORFILES /P D:Doc\ /M *.txt /D -366 /C "del @path"


Report •

#7
June 25, 2010 at 18:13:57
I have never done anything with DOS till now, just googled it and it had the second cmd and it worked fine until it gave the file not found error this morning :-).

I will try your suggestion.


Report •

#8
June 25, 2010 at 18:18:02
The error comes over STDERR, not STDOUT. Because it's an error message.
You must handle this like so:
FORFILES /P D:Doc\ /M *.txt /D -366 /C "cmd /c del @path" 2>&1 | find /v /i "ERROR: No files found with the specified search criteria."

nbrane: any reason you're using a second CMD process?
FORFILES is not a built-in CMD command, so FORFILES must spawn its own CMD if you wish to use built-in CMD commands.


Report •

#9
June 25, 2010 at 18:28:09
Hi Razor2.3,

FORFILES /P D:Doc\ /M *.txt /D -366 /C "cmd /c del @path" 2>&1 | find /v /i "ERROR: No files found with the specified search criteria."

This worked!!!

Thanks a lot.


Report •

#10
June 25, 2010 at 18:40:03
I see on google that

2>&1 is used to to merge Standard Output and Standard Error and redirect them together to a single file.

But what does that mean?


Report •

#11
June 25, 2010 at 21:37:05
That's . . . slightly inaccurate; the output isn't being dumped to a file. We're just sending STDERR to the same place where we send STDOUT. In this case, we're passing both streams to FIND.

Report •


Ask Question