Christiaan
Board Regular
- Joined
- Nov 5, 2012
- Messages
- 81
Hello Board Members!
I am looking for a way to count files in a specified folder that are created on or before a certain date.
I need to do this for 2 file types (*.xlsx and *.PDF), that reside in two different folders.
This is the code I have to count ALL files in the folders:
Counting ALL the files in the 'evaluation' and 'pdf' folder works just fine. I am looking for the additional code to do a count if the date is before 'purgedate'.
Any tips are greatly appreciated!
I am looking for a way to count files in a specified folder that are created on or before a certain date.
I need to do this for 2 file types (*.xlsx and *.PDF), that reside in two different folders.
This is the code I have to count ALL files in the folders:
Code:
Sub CountFiles()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
'Set the paths
Dim PathEvaluations As String
Dim PathPDF As String
Dim PathA As String
Dim PathB As String
Dim CountEvaluations As Integer
Dim CountOldEvals As Integer
Dim CountPDF As Integer
Dim CountOldPDF As Integer
Dim MsgBoxTitle As String
Dim PurgeDate As Date
PathEvaluations = Worksheets("References").Range("B50").Value
PathPDF = Worksheets("References").Range("B51").Value
MsgBoxTitle = Worksheets("References").Range("B32").Value
PurgeDate = Worksheets("References").Range("B77").Value
'Count evaluation files
PathA = PathEvaluations & "*.xlsx"
Filename = Dir(PathA)
Do While Filename <> ""
CountEvaluations = CountEvaluations + 1
Filename = Dir()
Loop
'Count PDF files
PathB = PathPDF & "*.pdf"
Filename = Dir(PathB)
Do While Filename <> ""
CountPDF = CountPDF + 1
Filename = Dir()
Loop
MsgBox "System maintenance:" & vbNewLine & vbNewLine & _
CountEvaluations & " files found in: evaluations folder" & vbNewLine & _
"of which " & CountOldEvals & " are from before: " & PurgeDate & " and can be deleted!" & vbNewLine & vbNewLine & _
CountPDF & " files found in: pdf folder" & vbNewLine & _
"of which " & CountOldPDF & " are from before: " & PurgeDate & " and can be deleted!", vbInformation, MsgBoxTitle
End Sub
Counting ALL the files in the 'evaluation' and 'pdf' folder works just fine. I am looking for the additional code to do a count if the date is before 'purgedate'.
Any tips are greatly appreciated!