Cleanup Old MySQL backups on Windows for AppManager

This will delete all backup files and folders older than 5 days

Path1 = "E:AppManager8workingbackup"


Dim fso
Dim oFolder
Dim oFile
Dim oSubFolder

Set fso = createobject("Scripting.FileSystemObject")

Set oFolder = fso.GetFolder(Path1)

For Each oFile In oFolder.files
If DateDiff("d", oFile.DateCreated,Now) > 5 Then
oFile.Delete True
End If
Next


'Set oFolder = fso.GetFolder(Path2)
' For Each oFile In oFolder.files
' If DateDiff("d", oFile.DateCreated,Now) > 30 Then
' oFile.Delete True
' End If
' Next

Set oFolder = Nothing

'The script will stop running here if you uncomment Wscript.Quit.
'Leave the next line commented if you need to delete subdirectories from the given path.
'Wscript.Quit

Set oFolder = fso.GetFolder(Path1)
Set colSubfolders = oFolder.Subfolders

For Each oSubfolder in colSubfolders
If DateDiff("d", oSubFolder.DateCreated,Now) > 5 Then
fso.DeleteFolder(oSubFolder)
End If
Next

Set oSubFolder = Nothing
Set oFolder = Nothing
Set fso = Nothing
Wscript.Quit

No comments: