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

早上同事转给我一封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 *******************

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...