Scripting help: Deleting files more than 3 days old

I have the following script (SEE BELOW) running to automate my backups using 2003 Server.  The script makes th ebackup, then copies the bkf to a remote server.

The last peice of the puzzle is to do some cleanup

1. delete the bkf files that reside in the source folder one they are copied to the source folder
2.  Delete any bkfs older than3 days so I always have the last 3 backups availlable for restore.
********************************************************************************************************************
@for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do  @set dt=%%i-%%j-%%k-%%l
@set dt=%dt%
@echo Copying backup set:  %dt%.
@echo Please wait...
@ntbackup.exe backup "@C:\Documents and Settings\Administrator\Local Settings\Application Data\Microsoft\Windows

NT\NTBackup\data\backup set.bks" /a /d "STVPCSG01 %dt%" /v:no /r:no /rs:no /hc:off /m normal /j "%dt%" /l:s /f

"c:\Auto Backups\STVPCSG01 %dt%.bkf"


@for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do  @set dt=%%i-%%j-%%k-%%l
@set dt=%dt%
@echo Sending backup file to STVPDPM01. Please wait...
@xcopy "c:\Auto Backups\STVPCSG01 %dt%.bkf" "\\STVPDPM01\DMZ$" /Y
@echo Finished.


pflechaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

popularbhaskarCommented:
try the FORFILES.EXE server resource kit tool - works on NT, 2000, XP, 2003, etc

example:
FORFILES -pc:\foldername -s -m*.* -d-30 -c"CMD /C del @FILE"

-p = path
-s = include subdirs
-m = match filetype
-d = age in days (can also be set as an absolute date ie DDMMYYYY)
-c = command to execute

Note there are no spaces between the switches and their arguments.
info here:
http://www.jsiinc.com/SUBL/tip5600/rh5645.htm
Download it here:
http://www.dynawell.com/support/ResKit/winnt.asp
http://www.dynawell.com/support/ResKit/

--popularbhaskar
0
pflechaAuthor Commented:
It is deleting all files regardless of the date of the file

FORFILES /p "D:\DMZ$" /D -5 /M *.vhd -c "CMD /c del *.vhd"

Does the -5 mean to delete any files older than 5 days?  That is my goal.
0
pflechaAuthor Commented:
Does anybody have experience using the FORFILES to delete files older than a specific date?  I need to automate the capacity management of a specific folder.   Any files older than 5 days need to be deleted.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

pflechaAuthor Commented:
The command I am trying is

FORFILES /p "c:\backups" /D -5 "cmd /c *.bkf"
0
pflechaAuthor Commented:
Does anybody know how I can  automate the deletion of these files?
0
pflechaAuthor Commented:
OK I figured it out.


Forfiles -p D:\FOLDER -m *.bkf -d -10 -c "CMD /C del @file"
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.