Submitted By: Manupriya Jayathilake

Deletes old log files from log folders

Visual Basic
Edit|Remove
'This script delete old logs files from a log folder 

'Submitted by Manupriya Jayathilake


Dim fs, f, s 
TargetFolder = "d:\logs\" 
Set objShell = CreateObject("Shell.Application")
Set fs = CreateObject("Scripting.FileSystemObject") 
Set objFolder = objShell.Namespace(TargetFolder) 
Set colItems = objFolder.Items

For i = 0 to colItems.Count - 1
filespec=colItems.Item(i)
Set f = fs.GetFile(TargetFolder & filespec) 
'deletes 2 days old logs can set any value depending on your requirement
If f.DateLastModified  < Now()-2 Then f.Delete
Next