7,763
社区成员
发帖
与我相关
我的任务
分享
Sub DelLogFile(ByVal strPath$)
Dim lDelDate&, lFileDate&, strFile$, strDate$
If (Asc(Right$(strPath, 1)) <> 92) Then strPath = strPath & "\"
lDelDate = Int(Now()) - 6
strFile = Dir$(strPath & "*.log")
Do While (Len(strFile) > 0)
strDate = Left$(Right$(strFile, 12), 8)
If (Len(strDate) = 8) Then
If (Val(strDate) > 0) Then
lFileDate = CDate(Format$(strDate, "0000-00-00"))
If (lFileDate < lDelDate) Then
Kill strPath & strFile
End If
End If
End If
strFile = Dir$()
Loop
End Sub
Option Explicit
Sub Main()
Dim dt As Date, sFileName As String, sOldFileName As String
dt = Date - 7
sOldFileName = "Test" & Format$(dt, "yyyymmdd") & ".log"
sFileName = Dir("D:\Log\*.log")
While LenB(sFileName) <> 0
If (sFileName Like "Test########.log") And (sFileName <= sOldFileName) Then
Kill "D:\Log\" & sFileName
End If
sFileName = Dir()
Wend
End Sub