I need to automate deleting files from a directory tree that are over 150 days old. I found the code below which I'm using as a proof of concept. It processes the files in the root but I can't figure out how to go below the root directory.
What do I need to add to recurse the rest of the folders?
Code:
Dim objFSO As New FileSystemObject
Dim objFile As File
Dim objFolder As Folder
Set objFolder = objFSO.GetFolder("Root Directory Path")
For Each objFile In objFolder.Files
List1.AddItem objFile.Name & ", " & objFile.DateCreated
If DateDiff("d", objFile.DateCreated, Date) > 150 Then
List2.AddItem objFile.Name & ", " & objFile.DateCreated
End If
DoEvents
Next objFile
Set objFSO = Nothing
Set objFile = Nothing
Set objFolder = Nothing