James 发表于 2017-12-27 21:32:30

IIS日志清理(VBS版,JS版)

'IIS日志清理VBS版代码(DelIISLog.vbs)  
'调用方法:DelIISLog "IIS日志所在路径",保留多少天的IIS日志
  
'遍历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 "C:\WINDOWS\system32\LogFiles",180 '遍历
  
页: [1]
查看完整版本: IIS日志清理(VBS版,JS版)