删除iis日志(deliislogs.vbs)

时间:2023-03-08 16:33:17

'path 目录

'ext 文件扩展名
'expiredDays 保留多少天以内的文件
Sub LogCleaner(path,ext,expiredDays)

On Error Resume Next

Set oFso = CreateObject("Scripting.FileSystemObject")

If Not oFso.FolderExists(path) Then Exit Sub '目录不存在退出

Set oFolder = oFso.GetFolder(path)

For Each oFile In oFolder.Files '处理目录下所有文件

'判断文件类型及最后修改日期
If right(oFile.name,3)=ext And DateDiff("d",oFile.DateLastModified,Date) > expiredDays Then oFile.delete

Next

For Each oSubFolder In oFolder.SubFolders '递归处理子文件夹

LogCleaner oSubFolder.Path,ext,expiredDays

Next

End Sub

'删除两个月之前的IIS日志
LogCleaner "C:\WINDOWS\system32\LogFiles\","log",60