Sub Balayage()
Const Dossier As String = "C:\Backup\"
Effacer Dossier, True
End Sub
Sub Effacer(ByVal Dossier As String, ByVal InclureSousDossiers As Boolean)
Dim FSO As Scripting.FileSystemObject
Dim DossierSource As Scripting.Folder, SousDossier As Scripting.Folder
Dim Fichier As Scripting.File
Set FSO = New Scripting.FileSystemObject
Set DossierSource = FSO.GetFolder(Dossier)
For Each Fichier In DossierSource.Files
If DateDiff("D", Fichier.DateLastModified, Now) >7 Then Fichier.Delete
Next Fichier
If InclureSousDossiers Then
For Each SousDossier In DossierSource.SubFolders
Effacer SousDossier.Path, True
If SousDossier.Files.Count = 0 Then SousDossier.Delete
Next SousDossier
End If
Set Fichier = Nothing
Set DossierSource = Nothing
Set FSO = Nothing
End Sub
|