i think this helps you very well
Option Explicit
'Delete all SQL Server backup files more than 1 days old
Dim oFS, oSQLBackupFol, oFol, oFil
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oSQLBackupFol = oFS.GetFolder("D:\SQL Server Backups") ' Change this to the right path
For Each oFol IN oSQLBackupFol.SubFolders
For Each oFil in oFol.Files
If oFil.DateCreated < Now-1 Then
'If you want to make sure it's a .bak or .trn file, check oFil.Name, otherwise
'This will delete anything more than a day old in the directory
'all first level subdirectories. (Recursion is left as an exercise for the reader)
oFil.Delete
End If
Next
Next
↧