'遍历IIS日志文件夹下的所有文件及子文件夹下的文件
Function DelIISLog(IISLogPath,KeepDays)
on error resume next
Set oFso = CreateObject(“Scripting.FileSystemObject”)
Set oFolder = oFso.GetFolder(IISLogPath)
Set oSubFolders = oFolder.SubFolders '得到该目录下所有的文件夹的集合
Set oFiles = oFolder.Files '得到该目录下所有的文件的集合
'第一步处理当前目录下的所有文件
For Each oFile In oFiles '遍历所有文件
if right(oFile.name,3)=“log” then
oDate=cdate(“20” & mid(oFile.name,3,2) & “-” & mid(oFile.name,5,2) & “-” & mid(oFile.name,7,2))
if date-oDate > KeepDays then oFile.delete '判断是不是要处理的IIS日志文件,如果是的话直接删除
end if
Next
'第二步处理当前目录下的所有目录,进行递归调用
For Each oSubFolder In oSubFolders
DelIISLog oSubFolder.Path,KeepDays '递归
Next
End Function
DelIISLog “E:\logs”,20 '遍历
09-21
2018
10-31
2004
06-22
2376