dburrows1278
Technical User
For some reason the loop deleting the subfolders isn't working. If I comment out the IF statement, it runs fine. The file portion runs without a hitch. What am I missing?
Code:
'Setup
Dim oFSO
Dim sDirectoryPath
Dim oFolder
Dim oDelFolder
Dim oFileCollection
Dim oFile
Dim iDaysOld
'Set the number of days to keep.
iDaysOld = 1
Set oFSO = CreateObject("Scripting.FileSystemObject")
sDirectoryPath = "\\server\share"
set oFolder = oFSO.GetFolder(sDirectoryPath)
set oFolderCollection = oFolder.SubFolders
set oFileCollection = oFolder.Files
'Walks through each file and folder in the archive folder.
'If it is older than the set date, then it is deleted.
For each oFile in oFileCollection
If oFile.DateLastModified < (Date() - iDaysOld) Then
oFile.Delete(True)
End If
Next
For each oDelFolder in oFolderCollection
If oDelFolder.DateLastModified < (Date() - iDaysOld) Then
oDelFolder.Delete(True)
End If
Next
'Clean up
Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing