用DIR函数(DIR(*.TXT))取文件名,去掉尾巴,
转成日期型,跟当前日期比较,大于60就删除。

解决方案 »

  1.   

    Sub KillFilesBefore60Day()
        Dim oDate As Date, oPath As String, oFile As String
        Dim oMon As Integer, oDay As Integer
        oPath = "C:"
        For i = 61 To 71 '总不会超过10天不开机吧
            oDate = Date + i
            oMon = Month(oDate)
            oDay = Day(oDate)
            oFile = oPath & "\" & Year(oDate) & IIf(oMon < 10, "0", "") & oMon & IIf(oDay < 10, "0", "") & oDay & ".txt"
            If Dir(oFile) = "" Then
               Debug.Print oFile & "不存在"
            Else
               Kill oFile
            End If
        Next
    End Sub