MsgBox ShowFolderList(Path),vbInformation,"Fichiers supprimés du répertoire"
Function ShowFolderList(strPath)
Dim fso, Dossiers, fic, fichiers, strListe, f, fdate, fname, dtDiffFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set Dossiers = fso.GetFolder(path)
Set fic = Dossiers.Files
For Each fichiers in fic
Set f = fso.GetFile(fichiers)
'If fso.GetExtensionName(fichiers) = "txt" Then
fdate = f.DateLastModified ' DateCreated ou DateLastAccessed ou DateLastModified
fname = f.Name
dtDiffFile = DateDiff("d", Now, fdate)
If dtDiffFile <= -7 Then
' MsgBox "Le fichier " & Path & fname & " sera supprimé car créé le " & fdate
strListe = strListe & vbcrlf & fname & " " & fdate
' fso.DeleteFile(Path & fname)
Else
' MsgBox "Le fichier " & Path & fname & " ne sera pas supprimé car créé le " & fdate
End If
'End If
Next
ShowFolderList = "Fichiers supprimés" &vbCrLf&"et"&vbCrLf&_
"DateLastModifiedModified > 7 jours"&vbCrLf&vbCrLf& strListe
Set fso = Nothing
Set Dossiers = Nothing
Set f = Nothing
End Function