Home » RDBMS Server » Server Administration » how to create a vb script that deletes files older than 7 days??
how to create a vb script that deletes files older than 7 days?? [message #56874] Thu, 01 May 2003 15:07 Go to next message
fengq
Messages: 38
Registered: October 2002
Member
Hi

I want to write a VB script that can delete all the archive log files that older than 7 days. so I can use jobs to schedule this happens every day automaticly.

Thanks for your help
Re: how to create a vb script that deletes files older than 7 days?? [message #56877 is a reply to message #56874] Fri, 02 May 2003 00:50 Go to previous messageGo to next message
Trifon Anguelov
Messages: 514
Registered: June 2002
Senior Member
The easier way is to have seven one line batch files. Each one copy the previous day archived logs in a separate directories (mon, tue, wed, etc.). Then deletes the one week old directory's files.

You can schedule it with "at'. Why go for VB code, compile it, etc...

Hope that helps,

clio_usa
OCP - DBA

Visit our Web site

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 Go to previous message
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
Previous Topic: Problem ReCreating ControlFile (urgent)
Next Topic: OS on C drive down, Oracle is on D, How will i recover?
Goto Forum:
  


Current Time: Mon Dec 30 17:33:55 CST 2024