Monday, March 19, 2012

Delete all backup files older than specified days.

Use below script to delete all backup files older than specified days.

Option Explicit
on error resume next
Dim intDaysOld
Dim strDirectoryPath
Dim objFSO
Dim objFolder
Dim objFileCollection
Dim objFile

'Customize values here to fit your needs
intDaysOld = 3
Set objFSO = CreateObject("Scripting.FileSystemObject")
strDirectoryPath = "\\Backup\SQL_Server\"
set objFolder = objFSO.GetFolder(strDirectoryPath)
set objFileCollection = objFolder.Files

'Walk through each file in this folder collection.
For each objFile in objFileCollection
If objFile.DateLastModified < (Date() - intDaysOld) Then
End If

'Clean up
Set objFSO = Nothing
Set objFolder = Nothing
Set objFileCollection = Nothing
Set objFile = Nothing

No comments:

Post a Comment