
Script to delete files older than a specific date in a directory
: Hi there,
: I have application on window 2000 that will create hundreds of file each
: day. I would like to schedule a daily task to delete files older than a
: certain date, e.g. a week from today.
: Please advise what alternatives I can do this.
: Thanks in advance.
:
Try this
Option Explicit
dim fso, file, daysBack, toDelete(100000), i, ii
daysBack = 7
Set fso = CreateObject("Scripting.FileSystemObject")
For Each file In fso.GetFolder("C:\test\").files
If DateValue(file.datelastModified) < DateValue(Now - daysBack) Then
toDelete(i) = file.Path
i = i + 1
End If
Next
for ii = 0 to i-1
fso.DeleteFile (toDelete(ii))
next
Set fso = Nothing
msgbox "complete"