Deleting log files older than current date 
Author Message
 Deleting log files older than current date

I have a directory where all logfiles are stored, how can i write a
script that will delete all old logfiles.


Mon, 09 Jun 2003 04:01:29 GMT  
 Deleting log files older than current date
Try the following. Change the log directory and delete date.

If you want to delete any file older than the current (today's) date use. .
.

dDelDate = Date

[--- Begin: Delete Old Logs.Vbs ---]

001.   Option Explicit
002.
003.   Dim oFS, sLogDir, dDelDate
004.
005.   Set oFS = WScript.CreateObject("Scripting.FileSystemObject")
006.
007.   sLogDir = "C:\Logs"
008.   dDelDate = #11/30/2000#
009.
010.   Call DelOldLogs(oFS.GetFolder(sLogDir))
011.
012.   MsgBox "All Done!"
013.   WSCript.Quit
014.
015. '---------------------
016.   Sub DelOldLogs(oFolder)
017.     Dim oFile, oSubFolder
018.
019.     For Each oFile In oFolder.Files
020.       On Error Resume Next
021.       If IsOlder(oFile, dDelDate) Then oFile.Delete
022.     Next
023.     ' Process any sub folders
024.     For Each oSubFolder In oFolder.SubFolders
025.       Call DelOldLogs(oSubFolder)
026.     Next
027.   End Sub
028.
029. '---------------------
030.   Function IsOlder(oFile, dDelDate)
031.     If oFile.DateLastModified < dDelDate Then
032.       IsOlder = True
033.     Else
034.       IsOlder = False
035.     End If
036.   End Function

[--- End: Delete Old Logs.Vbs ---]


Quote:
> I have a directory where all logfiles are stored, how can i write a
> script that will delete all old logfiles.



Sun, 15 Jun 2003 07:30:10 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. deleting logfiles older than current date

2. Script to delete files older than a specific date in a directory

3. Script to delete files older than a specific date in a directory

4. Deleting files and folders older than a particular date

5. delete records that are older than a certain date

6. Deleting old files

7. Delete Files 3 days old

8. Find files in a folder and delete them if older then 2 dayx

9. Delete files older than n days.

10. Delete oldest file

11. Creating a log file of files that have been deleted

12. VBS to delete files in a directory older than 30 days

 

 
Powered by phpBB® Forum Software