|
|
Re: how to create a vb script that deletes files older than 7 days, THE CODE [message #56956 is a reply to message #56874] |
Fri, 09 May 2003 01:13 |
Alex
Messages: 190 Registered: August 1999
|
Senior Member |
|
|
Dim fso
Dim fold 'As Folder
Set fso = CreateObject ("Scripting.FileSystemObject")
Set fold = fso.GetFolder("e:orantRdbms80trace")
Dim f 'As file
Dim filestodelete 'As New Dictionary
set filestodelete = CreateObject("Scripting.Dictionary")
For Each f In fold.Files
'If LCase(f.Name) Like "ora*.trc" Then
If Left(LCase(f.Name), 3) = "ora" And Right(LCase(f.Name), 4) = ".trc" Then
'If f.DateCreated <= DateAdd("d", -7, Now) Then '7 days back Created
'OR
If f.DateLastModified <= DateAdd("d", -7, Now) Then '7 days back Modified
filestodelete.Add filestodelete.Count, f.Name
End If
End If
Next
Dim i 'As Long
For i = 0 To filestodelete.Count - 1
'fso.DeleteFile(filestodelete.Item(i))
Next
MsgBox filestodelete.Count & " file deleted"
filestodelete.RemoveAll
Set fold = Nothing
Set filestodelete = Nothing
|
|
|