Delete files in folder older than specified date

I am using MySQL administrator to run nightly backups of my database.  Everything seems to be working fine, except that I don't need to keep backups for data that is older than 1 week old.

How can I run a batch script or other program that will automatically delete all files ending with .SQL that are more than 1 week old?  Thank you.
DanielAttardAsked:
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.

merowingerCommented:
This vbscript (.vbs) should do it. 7 = seven days
DaysOld = 7
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = oFSO.GetFolder("D:\Folder")
Set objFiles = objFolder.Files

For each objFile in objFiles
	If UCASE(Right(objFile.Name,4)) = ".SQL" Then 
		If objFile.DateLastModified < (Date - DaysOld) Then
			objFile.Delete(True)
		End If
	End If
Next

Open in new window

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
Bill PrewCommented:
If you are not opposed to using a small free utility DELAGE32 is a great little tool for this sort of thig.  Take a look at the following links.

http://home.mnet-online.de/horst.muc/win/delage.htm
http://home.mnet-online.de/horst.muc/wbat32.htm

~bp
0
Bill PrewCommented:
You can also use the FORFILES tool from Microsoft, take a look at:

http://technet.microsoft.com/en-us/library/cc753551(WS.10).aspx

~bp
0
DanielAttardAuthor Commented:
This simple code you provided works great.  Thank you.
0
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
VB Script

From novice to tech pro — start learning today.