Dim fso, sfolder, ofolder, oSubFolders
Set fso = CreateObject ("Scripting.FileSystemObject")
If fso.FolderExists(Root) Then
Set ofolder = fso.GetFolder(Root)
Set oSubFolders = ofolder.SubFolders
Set sfolder = Nothing
'ESAHMI.ESAMSGBOX Root
'ESAHMI.ESAMSGBOX CStr(ofolder)
ESAHMI.ESAMSGBOX ofolder
'ESAHMI.ESAMSGBOX oSubFolders
On Error Resume Next
Err.clear
' For Each folder in fso.GetFolder(Root).SubFolders
For Each sfolder in oSubFolders
If Err.Number <> 0 Then
ESAHMI.ESAMSGBOX Err.Number
Exit For 'If no permission or no subfolder in folder
End If
On Error goto 0
ESAHMI.ESAMSGBOX sfolder
ESAHMI.ESAMSGBOX oSubFolders
createdDate = FormatDateTime(sfolder.DateCreated, "2") 'Getting folder date 2 = vbShortDate - Returns date: mm/dd/yyyy
If (DateDiff("d", createdDate, Date) > MaxAgeInDays) Then
fso.GetFolder(sfolder).Copy sCustomerPicturesPath
fso.DeleteFolder sfolder, True
End If
Next