Delete old backups

Use this to delete old backup files from disk. Run as a job using Active X Script or as a .vbs file.

Option Explicit
on error resume next
 Dim oFSO
 Dim sDirectoryPath
 Dim oFolder
 Dim oFileCollection
 Dim oFile
 Dim iDaysOld

 iDaysOld = 5
 Set oFSO = CreateObject(“Scripting.FileSystemObject”)
 sDirectoryPath = “D:MSSQLbackup”
 set oFolder = oFSO.GetFolder(sDirectoryPath)
 set oFileCollection = oFolder.Files

‘Walk through each file in this folder collection.
‘If it is older than 5 days, then delete it.
 For each oFile in oFileCollection
  If oFile.DateLastModified < (Date() – iDaysOld) Then
  End If

‘Clean up
 Set oFSO = Nothing
 Set oFolder = Nothing
 Set oFileCollection = Nothing
 Set oFile = Nothing


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s