现在的位置: 首页 > 综合 > 正文

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

2013年08月19日 ⁄ 综合 ⁄ 共 891字 ⁄ 字号 评论关闭
早上同事转给我一封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 *******************

抱歉!评论已关闭.