02 February 2007

clsFSOFiles - VBA

Option Explicit

' a late binding wrapper class for FSO Files Collection
'


Private blnIndex As Boolean

Private objFSO As Object
Private col As VBA.Collection

Public Event FileIndexed(FSOFile As clsFSOFile)

' *****************************************************************************
Private Sub Class_Terminate()
Set col = Nothing
Set objFSO = Nothing
End Sub

' *****************************************************************************
Public Function Init(Files As Object) As clsFSOFiles
Set objFSO = Files
Set Init = Me
blnIndex = True
End Function

' *****************************************************************************
Public Function Count() As Long

If blnIndex Then Me.Index
Count = col.Count

End Function

' *****************************************************************************
Public Function Item(Index As Long) As clsFSOFile

If blnIndex Then Me.Index
Set Item = col.Item(Index)

End Function

' *****************************************************************************
Public Function Index() As clsFSOFiles

Dim objFile As Object
Dim objFSOFile As clsFSOFile

blnIndex = False
Set col = New VBA.Collection

For Each objFile In objFSO
Set objFSOFile = New clsFSOFile
col.Add objFSOFile.Init(objFile.Path)
RaiseEvent FileIndexed(objFSOFile)
Next objFile

Set objFile = Nothing
Set objFSOFile = Nothing

Set Index = Me

End Function