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?
 
merowingerConnect With a Mentor Commented:
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
 
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
All Courses

From novice to tech pro — start learning today.