VERSION 1.0 CLASS BEGIN MultiUse = -1 'True END Attribute VB_Name = "FileNameSet" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = True Attribute VB_PredeclaredId = False Attribute VB_Exposed = False Option Explicit Private FileNames As Collection 'Array of file names Public Property Get Count() As Long 'Returns number of names in FileNames list Attribute Count.VB_Description = "Returns number of names in FileNames list" Count = FileNames.Count End Property Public Sub CreateSet(Path As String, Mask As String) 'Creates FileNames list of all files matching Mask in the given Path Attribute CreateSet.VB_Description = "Creates FileNames list of all files matching Mask in the given Path" Dim FileName As String On Error GoTo CreateSetError FileName = Dir$(Path + Mask) 'look for first file While FileName <> "" 'loop through all files FileNames.Add Path + FileName 'add file to list FileName = Dir$ 'get next file matching mask Wend Exit Sub CreateSetError: Err.Raise Err.Number, "FileNameSet.CreateSet", Error$ + ". Error occurred while trying to find files matching " + Path + Mask End Sub Public Sub RemoveName(i) Call FileNames.Remove(i) End Sub Public Sub DeleteOld(DaysOld) 'Deletes files from FileNames list that are older than DaysOld days Attribute DeleteOld.VB_Description = "Deletes files from FileNames list that are older than DaysOld days" Dim i As Long For i = 1 To FileNames.Count If DateDiff("d", Now, FileDateTime(GetName(i))) > DaysOld Then Kill GetName(i) End If Next 'I End Sub Public Sub DeleteSet() 'Deletes all files in the FileNames list and clears the list Attribute DeleteSet.VB_Description = "Deletes all files in the FileNames list and clears the list" Dim i As Long For i = 1 To FileNames.Count Kill FileNames.Item(i) Next 'i While FileNames.Count > 0 FileNames.Remove (FileNames.Count) Wend End Sub Public Function GetName(Index) As String 'Returns the FileName matching the supplied Index value Attribute GetName.VB_Description = "Returns the FileName matching the supplied Index value" If FileNames.Count >= Index Then GetName = FileNames.Item(Index) Else GetName = "" End If End Function Private Sub Class_Initialize() 'Initializes the FileNames list Set FileNames = New Collection End Sub Private Sub Class_Terminate() 'Destroys the FileNames list While FileNames.Count > 0 FileNames.Remove (FileNames.Count) Wend Set FileNames = Nothing End Sub