首页 /编程语言和算法/VB6/ASP
 ASP 删除修改日期超过5天(5天前的历史文件/文件夹)的文件和子文件夹
2023年5月24日 16:19
<%
Const strPath = "D:\manongku\txt"
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

Call Search(strPath)

Response.Write "清理完毕!"

Sub Search(str)
    Dim objFolder, objSubFolder, objFile
    Set objFolder = objFSO.GetFolder(str)
    For Each objFile In objFolder.Files
        If objFile.DateLastModified < (Now() - 5) Then  '五天前的记录
            objFile.Delete (True)
        End If
    Next

    For Each objSubFolder In objFolder.SubFolders
        Search (objSubFolder.Path)
        ' 文件都清理了,现在看看
        ' 文件夹是否空的。
        If (objSubFolder.Files.Count = 0) Then
            objSubFolder.Delete True
        End If
    Next
End Sub
%>


 
全部回复(0)
首页 | 电脑版 |