I need a code to look in my C drive for specific folders.
I want it to go through the first folder and keep drilling in all the subfolders until it hits a dead end, and then go back to second folder and do the same etc..., looking for any folder or file older than 2 years and delete it.
This is the code I have:
Private Sub FileCleanUp(strPath As String) Dim m_objFSO As Scripting.FileSystemObject Dim objFolder As Scripting.Folder Dim objFile As Scripting.File Dim dDeleteDate As Date Dim sDirectorypath sDirectorypath = "C:\myfolder" 'what should I replace this with to look in ALL 'folders and subfolders? dDeleteDate = DateAdd("m", -3, Now()) Set m_objFSO = New Scripting.FileSystemObject Set objFolder = m_objFSO.GetFolder(strPath) For Each objFile In objFolder.Files If Format(objFile.DateLastModified, "YYYY-MM-DD") <= Format(dDeleteDate, "YYYY-MM-DD") Then m_objFSO.DeleteFile (strPath & objFile.Name) End If Next objFile Set m_objFSO = Nothing End Sub