VB Script 定期删除Web应用程序产生的Log

来源:互联网 发布:java 模拟post 编辑:程序博客网 时间:2024/06/07 08:49
早上同事转给我一封Mail说用户无法访问一个Web Servcie请我帮忙看看原因。 登录服务器查看Servcie已经是停止的,重启Servcie失败,查原因是Disk Space没有了。
原来这个应用程序每天都产生大量的Log文件也没有人清理过,从网上找了段脚步然后自己改了改做了一个Scheduled task job每天定时的清理旧的Log. Source Code如下:
'************ Start of Code **********************
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:\log"
' Specify Number of Days Old File to Delete
iDaysOld = 15
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sDirectoryPath)
Set oFileCollection = oFolder.Files
For each oFile in oFileCollection
'This section will filter the log file

If LCase(left(Cstr(oFile.Name), 8)) = "info.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
'**************** End of Code *******************
原创粉丝点击