我想删除 7 天前的文件和空文件夹。我从链接中使用了以下脚本,但是由于源直接指向驱动器号,因此某些文件和文件夹没有被删除。但是,如果我们更改源文件夹 c:\temp\lab 一切正常。
Const Active = True
Const sSource = "E:"
Const MaxAge = 7 'days
Const Recursive = True
Checked = 0
Deleted = 0
Set oFSO = CreateObject("Scripting.FileSystemObject")
if active then verb = "Deleting """ Else verb = "Old file: """
CheckFolder oFSO.GetFolder(sSource)
WScript.echo
if Active then verb = " file(s) deleted" Else verb = " file(s) would be deleted"
WScript.Echo Checked & " file(s) checked, " & Deleted & verb
Sub CheckFolder (oFldr)
For Each oFile In oFldr.Files
Checked = Checked + 1
If DateDiff("D", oFile.DateLastModified, Now()) > MaxAge Then
Deleted = Deleted + 1
WScript.Echo verb & oFile.Path & """"
If Active Then oFile.Delete
End If
Next
if not Recursive then Exit Sub
For Each oSubfolder In oFldr.Subfolders
CheckFolder(oSubfolder)
Next
End Sub