padinka.
Option Compare Database
Option Explicit
Type RetentionType
FileFolder As String 'path of folder
RetentionInterval As String ' 'w' for Week, "m" for month ...
NumIntervals As Integer '1 for daily; 2 for weekly, 3 for monthly ...
End Type
Function DeleteFiles()
Dim Retention(4) As RetentionType
Dim Idx As Integer
Dim FilIntvl As Integer
Dim MyFil As String
Dim FilStamp As Date
Retention(0).FileFolder = "C:\My Documents\" '"Your 'Daily' Path Here"
Retention(0).RetentionInterval = "ww"
Retention(0).NumIntervals = 1
Retention(1).FileFolder = "C:\My Documents\" '"Your 'Weekly' Path Here"
Retention(1).RetentionInterval = "ww"
Retention(1).NumIntervals = 2
Retention(2).FileFolder = "C:\My Documents\" '"Your 'Monthly' Path Here"
Retention(2).RetentionInterval = "m"
Retention(2).NumIntervals = 3
Retention(3).FileFolder = "C:\My Documents\" '"Your 'Quarterly' Path Here"
Retention(3).RetentionInterval = "m"
Retention(3).NumIntervals = 6
Retention(4).FileFolder = "C:\My Documents\" '"Your 'Annually' Path Here"
Retention(4).RetentionInterval = "m"
Retention(4).NumIntervals = 24
For Idx = 0 To UBound(Retention)
MyFil = Dir(Retention(Idx).FileFolder & "*.*"

'First File
While MyFil <> ""
If (MyFil = "." Or MyFil = ".."

Then
'Current or parent directory
GoTo NxtFil 'Skip Directories!
End If
If ((GetAttr(Retention(Idx).FileFolder & MyFil) And vbDirectory) = vbDirectory) Then
'Named (Sub) directory
GoTo NxtFil 'Skip Directories!
End If
FilStamp = FileDateTime(Retention(Idx).FileFolder & MyFil) 'Date-Time of File Modification
FilIntvl = DateDiff(Retention(Idx).RetentionInterval, FilStamp, Now())
If (FilIntvl > Retention(Idx).NumIntervals) Then
'Kill (Retention(Idx).FileFolder & MyFil)
Debug.Print "Old File: " & Retention(Idx).FileFolder & MyFil & " " & FilStamp
End If
NxtFil:
MyFil = Dir
DoEvents 'Chance to Break and see the activity
Wend
Next Idx
End Function
I "Commented Out" the Kill Statement - I certainly do not want to have this actually happen on MY system. You probably want to 'check' it out before using it "Live". To have it "DO IT", un-comment the kill statement (and, possibly, comment out the debug.print statement. Also, the paths to YOUR folders/directories need to be set appropiatly.
[red]This CODE is HAZZARDOUS. DO NOT play with it. Do NOT run it without understanding it.[/red]
MichaelRed
There is never time to do it right but there is always time to do it over.