' Find all backup files in the SQL backup folder we can safely delete.' "Safely delete" means:' - file creation date older than DaysToRetain days AND' - the archive bit has been cleared (meaning they've gone to tape)' Created 1/7/2011 as an alternative to the SQL Maintenance Plan task so that ' we can not only check that the backups are more than x days old, but also check ' that the archive bit has been cleared before deleting them!' Too many tape backup failures...' ======================================================================================' MODIFICATIONS' ======================================================================================' 2012-09-18: Changed path to new HD installed on server' ======================================================================================' How many days should we keep? DaysToRetain = 5 Set fso = CreateObject("Scripting.FileSystemObject") Set oFolder = fso.GetFolder("E:\SQLBackup")' ======================================================================================' Note the bitwise comparison: is Archive Bit not set (i.e., cleared). ' Don't use parentheses after "Not" or the script fails....For Each f In oFolder.Files If (LCase(Right(f.Name, 3)) = "bak" Or LCase(Right(f.Name,3)) = "trn") And _ f.DateCreated < DateAdd("d", (-1 * DaysToRetain), Date) And _ Not f.Attributes AND 32 Then f.Delete End IfNext