Last active
December 18, 2015 11:39
-
-
Save tekguy/5776885 to your computer and use it in GitHub Desktop.
VBScript to delete old .bak files from specified directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'============================== | |
'Remove old backups | |
'http://gordondurgha.com | |
'============================= | |
'Definitions | |
iDaysOld = 3 | |
strExtension = ".bak" | |
sDirectoryPath = "D:\MSSQL\Backups\" | |
Set oFSO = CreateObject("Scripting.FileSystemObject") | |
Set oFolder = oFSO.GetFolder(sDirectoryPath) | |
Set oFileCollection = oFolder.Files | |
'Walk through each file in this folder collection. | |
For each oFile in oFileCollection | |
If oFile.DateLastModified < (Date() - iDaysOld) Then | |
If Right(UCase(oFile.Name), Len(strExtension)) = UCase(strExtension) Then | |
oFile.Delete(True) | |
End If | |
End If | |
Next | |
'Clean up | |
Set oFSO = Nothing | |
Set oFolder = Nothing | |
Set oFileCollection = Nothing | |
Set oFile = Nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment