這是我的功能不起作用。它永遠不會進入刪除調用,因爲if語句永遠不會評估爲真,我無法弄清楚原因。刪除年齡大於特定年齡的文件夾
Function DeleteOldFolders(root, maxAgeInDays)
Dim fso, ofolder, subFolders
Set fso = CreateObject ("Scripting.FileSystemObject")
If fso.FolderExists(root) Then
Set ofolder = fso.GetFolder(root)
Set subFolders = ofolder.SubFolders
For Each folder in subFolders
createdDate = FormatDateTime(folder.DateCreated, "2")
If (DateDiff("d", createdDate, Date) > maxAgeInDays) Then
objFSO.DeleteFolder folder, True
End If
Next
End If
Set objFSO = Nothing
End Function