02 February 2007

clsFSOFolders - VBA

Option Explicit

' a late binding wrapper class for FSO Folders collection object
'


Private objFolders As Object
Private strFolders() As String

Public Event FolderIndexed(FSOFolder As clsFSOFolder)

' *****************************************************************************
Private Sub Class_Terminate()
Set objFolders = Nothing
End Sub

' *****************************************************************************
Public Function Init(Folders As Object) As clsFSOFolders
Set objFolders = Folders
Set Init = Me
ReDim strFolders(0)
End Function

' *****************************************************************************
Public Function Count() As Long
Count = objFolders.Count
End Function

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

Dim objFold As clsFSOFolder

Set objFold = New clsFSOFolder
Set Item = objFold.Init(strFolders(Index))
Set objFold = Nothing

End Function

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

Dim objFolder As Object
Dim lngItem As Long

ReDim strFiles(1 To objFolders.Count)

lngItem = 1
For Each objFolder In objFolders
strFiles(lngItem) = objFolder.Path
RaiseEvent FolderIndexed(Me.Item(lngItem))
lngItem = lngItem + 1
Next objFolder

Set objFolder = Nothing
Set Index = Me

End Function