Option Explicit
On Error Resume Next
Dim oFSO, oFolder, sDirectoryPath
Dim oFileCollection, oFile, sDir
Dim iDaysOld
'' Specify Directory Path From Where You want to clear the old files
sDirectoryPath = "C:\ETL\LOGFiles"
'' Specify Number of Days Old File to Delete
iDaysOld = 0
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sDirectoryPath)
Set oFileCollection = oFolder.Files
For each oFile in oFileCollection
If LCase(Right(Cstr(oFile.Name), 3)) = "log" Then
If oFile.DateLastModified < (date() - iDaysOld) Then
oFile.Delete(True)
End If
End If
Next
Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing
No comments:
Post a Comment