delete x days of files Windows server 2003 sp2
535 pts.
0
Q:
delete x days of files Windows server 2003 sp2
I am trying to use ForFiles to delete files in a folder that contains file older than 30 days. I am using Windows 2003 server. This is what i am getting on the DOS screen

C:temp>Windows 2003 u Forfiles
'Windows' is not recognized as an internal or external command, operable program or batch file.

C:temp>ECHO **** DELETING FILES ****

C:temp>forfiles /p c:test072909 /s /m *.* /d -30/c "cmd /c del echo @file"
ERROR: Invalid argument/option - 'cmd /c del echo @fiile'.Type "FORFILES /?" for usage.

This is in my batch script
Windows 2003 – ForFiles
ECHO ***** DELETING FILES *****

forfiles /p c:test072909 /s /m *.* /d -10/c "cmd /c del echo @file"

pause

Software/Hardware used:
Windows 2003 SP2
ASKED: Aug 26 2009  2:23 PM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
29855 pts.
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
First, remove the "Windows 2003 – ForFiles" line from your script.

Then, try changing your forfiles call to this:

forfiles /p c:\test072909\ /s /m *.* /d -30 /c "cmd /c del @file"


If you just want to list the files, then use this:

forfiles /p c:\test072909\ /s /m *.* /d -30 /c "cmd /c echo @file"



A blank space was missing before "/c", and you were trying to execute two commands (del and echo).
Last Answered: Aug 26 2009  3:03 PM GMT by Carlosdl   29855 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Kwt712   535 pts.  |   Aug 26 2009  3:37PM GMT

Great, it worked thanks for the help. I do have one question. Is there a way to download ForFiles to make it work on WinXP Professional SP2. I cannot have the same script work off of my desktop. Any recommendations.

Thanks

 

Kwt712   535 pts.  |   Aug 26 2009  3:59PM GMT

ok, i have a problem now, i just put this on a production server

Windows 2003 SP2 … this is what i am getting now when i run a script against the foler

C:Batch File>ECHO ***** Files1F:userDischarge forms - savedCompleted *****

***** Files1F:userDischarge forms - savedCompleted *****

C:Batch File>ECHO ***** DELETING FILES *****
***** DELETING FILES *****

C:Batch File>forfiles /p “F:userDischarge forms - savedtest” /s /m *.* /d -
25 /c “cmd /c del @file”
ERROR: Invalid argument/option - ‘@file’.
Type “FORFILES /?” for usage.

C:Batch File>pause
Press any key to continue . . .

I have 2 folders one is completed that the script will run against and the other one is test with same files in them. I have files dated 7/11/2009 and the script will not clean them up. where did i go wrong here now.

thanks

 

Carlosdl   29855 pts.  |   Aug 26 2009  4:52PM GMT

Can you post the contents of your script file ? (not the results when running it)

Thanks,

 

Kwt712   535 pts.  |   Aug 26 2009  5:13PM GMT

here you go

ECHO ***** Files1F:userDischarge forms - savedCompleted *****

ECHO ***** DELETING FILES *****

forfiles /p “F:userDischarge forms - savedtest” /s /m *.* /d -25 /c “cmd /c del @file”

pause

ALSO, is it possible to make ForFiles to work with XP. If yes, then how.

Thanks

 

Carlosdl   29855 pts.  |   Aug 26 2009  6:17PM GMT

The problem seems to be the double quotes (”) in the path.

You could try changing directory first, and then executing forfiles.

Something like this:

F:
cd “F:userDischarge forms - savedtest”
forfiles /s /m *.* /d -25 /c “cmd /c del @file”

 

Carlosdl   29855 pts.  |   Aug 26 2009  6:44PM GMT

There is a version you can download that runs on XP, but it is not the same version as the one included in Server 2003 or 2008, and the syntax is not the same.

You can download it from here.

Basically, you use “-” instead of “/” to specify the parameters, and you can’t have blank spaces between the parameter option and the parameter itself. The @file variable must be in Uppercase.

You would need to change your script to something like this:

cd “F:userDischarge forms - savedtest”
forfiles -s -m*.* -d-25 -c”cmd /c del @FILE”

 

Kwt712   535 pts.  |   Aug 26 2009  6:48PM GMT

The ForFiles for Windows XP. It is only 12kb. Does that file needs to be in a certain directory for it to work.

thanks

 

Carlosdl   29855 pts.  |   Aug 26 2009  7:42PM GMT

Yes, it is a small program.

It should be in a directory included in your PATH environment variable, for example “C:windowssystem32″

 

Kwt712   535 pts.  |   Aug 27 2009  12:50PM GMT

can you tell me where exactly i need to put this file, i already copy it in C:windowssystem32 folder. Let me know.

thanks

 

Carlosdl   29855 pts.  |   Aug 27 2009  2:38PM GMT

and … did it work ?

You can put it wherever you want, but you have to make sure that path is included in your PATH environment variable.

 

Kwt712   535 pts.  |   Aug 27 2009  3:14PM GMT

ok let me get this straight … under Environment Variable, i have a User Variables and System Variables … i am guessing that the forfiles will be under user variables as C:windowssystem32forfiles.exe

let me know if i have this right.

thanks

 
0