FORFILES error, "The system cannot find the file specified"


C

Curious

Hi,

I've created a scheduler job with FORFILES command to delete files
older than certain days old. My job definition is as below:

\\DEVCRP01 forfiles /P "d:\CRPCORE\ServiceLogs" /M *.* /D
-30 /S /C "del @FILE"

But the job failed because of "ERROR: The system cannot find the file
specified.". See error details below:

-------------------------------------------------Complete
Error----------------------------------------------------------
PsExec v1.55 - Execute processes remotely
Copyright (C) 2001-2004 Mark Russinovich
Sysinternals - www.sysinternals.com

ERROR: The system cannot find the file specified.
ERROR: The system cannot find the file specified.
Connecting to
DEVCRP01...

Starting PsExec service on
DEVCRP01...

Connecting with PsExec service on
DEVCRP01...

Starting forfiles on
DEVCRP01...

forfiles exited on DEVCRP01 with error code 1.

Completed at 6/7/2007 3:11:21 PM
-------------------------------------------------Complete
Error----------------------------------------------------------

Anyone can tell me what's wrong? Thanks!
 
H

Herb Martin

Curious said:
Hi,

I've created a scheduler job with FORFILES command to delete files
older than certain days old. My job definition is as below:

\\DEVCRP01 forfiles /P "d:\CRPCORE\ServiceLogs" /M *.* /D
-30 /S /C "del @FILE"
@file resolves to ONLY the filename (with exe) without the Path.

@path gives the full path\filename.

You can more easily test by switching to Echo something like this:

forfiles /p d:\loads /m *.exe /c "cmd /c echo del @file"
forfiles /p d:\loads /m *.exe /c "cmd /c echo del @path"

....until you get roughly what you need.

Once you see that you have the "right stuff" you can remove the
prefixed Echo (and sometimes the cmd /c if it is not a built-in command.)

Also, watch out for paths on commands as many times the path environment
variable is NOT what you expect when working remote or in scheduled
jobs.
 
C

Curious

Hi Herb,

I've tried your suggested method to use echo and to use @PATH:

\\DEVCRP01 forfiles /P "d:\CRPCORE\ServiceLogs" /M *.* /D
-60 /S /C "cmd /c echo del @PATH"

The job completed successfully but no file was deleted.

Then I tried to use @FILE with echo:

\\DEVCRP01 forfiles /P "d:\CRPCORE\ServiceLogs" /M *.* /D
-60 /S /C "cmd /c echo del @FILE"

The job was successful but again, no file was deleted, but it
indicated a problem in the log:

The process tried to write to a nonexistent pipe. ========> The
process also writes something to a pipe?
Connecting to DEVCRP01...

Starting PsExec service on DEVCRP01...

Connecting with PsExec service on DEVCRP01...

Starting forfiles on DEVCRP01...

forfiles exited on DEVCRP01 with error code 0.
 
F

foxidrive

Hi Herb,

I've tried your suggested method to use echo and to use @PATH:

\\DEVCRP01 forfiles /P "d:\CRPCORE\ServiceLogs" /M *.* /D
-60 /S /C "cmd /c echo del @PATH"

The job completed successfully but no file was deleted.

Then I tried to use @FILE with echo:

\\DEVCRP01 forfiles /P "d:\CRPCORE\ServiceLogs" /M *.* /D
-60 /S /C "cmd /c echo del @FILE"

The job was successful but again, no file was deleted, but it
indicated a problem in the log:

The process tried to write to a nonexistent pipe. ========> The
process also writes something to a pipe?
Connecting to DEVCRP01...

Starting PsExec service on DEVCRP01...

Connecting with PsExec service on DEVCRP01...

Starting forfiles on DEVCRP01...

forfiles exited on DEVCRP01 with error code 0.
Your syntax is not what I've used in the past. Try this:


@echo off
:: Deletes files older than -nn days
:: days is the number of days ago (set days=-30)
:: change "drv:\Source Folder" to your desired drive and folder
:: fs is the filespec (*.*)
:: set s=-s to recursively process folders
:: remove -s to make it process only the current folder
:: remove ECHO after testing because at the moment it will
:: only echo the filenames to the screen.
:: download forfiles from
:: ftp://ftp.microsoft.com/reskit/y2kfix/x86/forfiles.exe
setlocal
echo Processing, please wait...
set p1=%comspec% /C if not @ISDIR
set p2=ECHO del 0x22@PATH\@FILE0x22
set days=-30
set from="drv:\Source Folder"
set fs=*.*
set s=-s
FORFILES -p%from% -m%fs% -d%days% %s% -c"%p1%==TRUE %p2%"
echo Done!
 
H

Herb Martin

Curious said:
Hi Herb,

I've tried your suggested method to use echo and to use @PATH:
The point of the "echo" was just to TEST the command locally at the
comman prompt so that you can SEE what WOULD happen, as echo
is just a convenient way to print a command instead of executing it --
and you can just pull the echo to turn the command into a real one.
 
C

Curious

After some experiments, I've decided that the following works:

\\DEVCRP01 forfiles /P "d:\CRPCORE\ServiceLogs" /M *.* /D -30 /S /C
"cmd /c del @FILE"

while the following fails to delete any files:

\\DEVCRP01 forfiles /P "d:\CRPCORE\ServiceLogs" /M *.* /D -30 /S /C
"del @FILE"

The only difference is that one uses "cmd /c del @FILE" while the
other uses "del @FILE". I was advised that "cmd /c del @FILE" was not
good because it launches a separate DOS command window for each file
it deletes. But that's the best I can get at this point.
 
H

Herb Martin

Curious said:
After some experiments, I've decided that the following works:

\\DEVCRP01 forfiles /P "d:\CRPCORE\ServiceLogs" /M *.* /D -30 /S /C
"cmd /c del @FILE"

while the following fails to delete any files:

\\DEVCRP01 forfiles /P "d:\CRPCORE\ServiceLogs" /M *.* /D -30 /S /C
"del @FILE"
Both Del and Echo are INTERNAL commands, i.e., part of CMD.exe and
cannot "run" without Cmd.exe (or some similar command processor) running.
The only difference is that one uses "cmd /c del @FILE" while the
other uses "del @FILE". I was advised that "cmd /c del @FILE" was not
good because it launches a separate DOS command window for each file
it deletes. But that's the best I can get at this point.
It does that -- and would be a lot less efficient if deleting a lot of files
(e.g., 100s, or 1000s.)
 
G

Guest

I have a question regarding FORFILES that I was hoping you may be able to
offer some advise.

I use FORFILES regualry in many command scripts but I have found an issue
when the command is near the end of some scripts. The log file confirms it
has worked but it doesnt run the command I ask, in this case delete. If I
copy the FORFILES line and run it from the command prompt it works.

For example my line is \\%JSO%\JOBS\utils\forfiles145> -p"%ARCHIVDIR%" -m*.*
-dC-35 -s -v -c"CMD /C DEL ""@PATH\@FILE"""

C:\WINNT>\\SCHEDULESERVER\JOBS\utils\forfiles145
-p"\\ARCHIVESERVER\file\BD\LIVE" -m*.* -dC-35 -s -v -c"CMD /C DEL
""@PATH\@FILE"""
----- DIRECTORY : \\ARCHIVESERVER\file\BD\LIVE <\\ARCHIVESERVER\file\BD\LIVE>
processing command <CMD /C DEL
"\\ARCHIVESERVER\file\BD\LIVE\ADEGT-collections-file1-20070516.payme
nts.113737.txt
<\\ARCHIVESERVER\file\BD\LIVE\ADEGT--collections-file1-20070516.payme
nts.113737.txt> "> on file
ADEGT-collections-file1-20070516.payments.113737.txt
processing command <CMD /C DEL
"\\ARCHIVESERVER\file\BD\LIVE\ADEGT-collections-file1-20070516.payme
nts.123713.txt
<\\ARCHIVESERVER\file\BD\LIVE\ADEGT-collections-file1-20070516.payme
nts.123713.txt> "> on file
ADEGT-collections-file1-20070516.payments.123713.txt
2 file(s) processed
2 total file(s) processed

Unfortunately due to build policies I am unable to run Filemon on the server
in question to see why it fails.

Any advice you have would be appreciated.

Thanks
 
H

Herb Martin

CP33 said:
I have a question regarding FORFILES that I was hoping you may be able to
offer some advise.

I use FORFILES regualry in many command scripts but I have found an issue
Then you likely know it better than I and hopefully someone else will
respond;
I tend to use the basic For command and perhaps do /f with a directory
(bare)
listing in a quoted command for the ( files ) portion.
when the command is near the end of some scripts. The log file confirms it
has worked but it doesnt run the command I ask, in this case delete. If I
copy the FORFILES line and run it from the command prompt it works.
One suggestion "near the end" -- make sure that EVERY batch file has a full
CR/LF and then terminates. There USED to be a DOS bug that made
batch files without a final line ending fail there.
 
F

foxidrive

I have a question regarding FORFILES that I was hoping you may be able to
offer some advise.

I use FORFILES regualry in many command scripts but I have found an issue
when the command is near the end of some scripts. The log file confirms it
has worked but it doesnt run the command I ask, in this case delete. If I
copy the FORFILES line and run it from the command prompt it works.

For example my line is \\%JSO%\JOBS\utils\forfiles145> -p"%ARCHIVDIR%" -m*.*
-dC-35 -s -v -c"CMD /C DEL ""@PATH\@FILE"""
The forfiles examples specifies the 0x entry for characters like the double
quote. EG:

-c"CMD /C DEL 0x22@PATH\@FILE0x22"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top