Tuesday, August 07, 2007

Files that are older than 45 days old.

Here is a script for all those file server administrators. This script will find all files that are "created" more than 45 days ago and then delete them. I generally export the results to a text file for review, but that is totally up to you.

'This script is to find and then delete any files that are older than 45 days old
'Version 1.0

Set fso = CreateObject ("Scripting.FileSystemObject")

If WScript.Arguments.Count = 0 then
RecurseDirectory "."
Else
RecurseDirectory WScript.Arguments.Item(0)
End If

Sub Recursedirectory(strDir)
Set refFolder = fso.GetFolder(strDir)


'Process files in directory
For Each refFile in refFolder.Files
if cDate(refFile.DateCreated) <= now()-45 then
refFile.Delete


end if
Next

Then Recurse down directory tree
For Each refSubFolder in refFolder.SubFolders
RecurseDirectory refSubFolder.Path
if refSubFolder.Files.Count = 0 then
refSubFolder.Delete
End If
Next
end sub


'cscript //nologo 45days.vbs >> 45day.csv

No comments: