分类: WINDOWS
2011-08-12 10:58:15
将以下内容用.vbs保存,此脚本为保留10天的日志,将10天前的前160个文件删除,日志文件路径为
E:\LOGS\W3SVC1187051486\ ,以ex开头,.log为后缀的文件。
'脚本调用中"%comspec% /k作用是确保窗口打开或关闭, /k, /c;
'//保留10天的日志,将10天前的前160个文件删除
call deleteFile( 160,10)
'删除日志
sub deleteFile( startNum, endNum)
Dim fso, stamp, file
Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
for x =endNum to startNum
stamp = getDateStamp( x )
'日志格式
file = "ex" & stamp & ".log"
'日志目录
'MsgBox(file)
fso.deleteFile( "E:\LOGS\W3SVC1151486\" & file )
next
end sub
function getDateStamp( num )
Dim NewDate1
NewDate1 = DateAdd("d", -num, Date)
s_year = Right(CStr(year(NewDate1)),2)
no_month = month(NewDate1)
s_month = CStr(no_month)
If (no_month < 10) Then
s_month = "0" + CStr(no_month)
End If
no_day = day(NewDate1)
s_day = CStr(no_day)
If (no_day < 10) Then
s_day = "0" + CStr(no_day)
End If
getDateStamp= s_year+s_month+s_day
end function