VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsDirList"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' clsDirList: Generic Directory Search
Option Explicit

Public Event status(ByVal msg As String)

Private mtxtFilter As String
Private mtxtPats() As String
Private mtxtPatCnt As Integer
Public noCase As Boolean

Public Function header() As String
    If Len(mtxtFilter) = 0 Then
        header = "PATH" & vbTab & "FILE" & vbTab & "EXT" & vbTab & "SIZE" & vbTab & "CREATED"
    Else
        header = "PATH" & vbTab & "FILE" & vbTab & "LINE" & vbTab & "TEXT"
    End If
End Function

Public Sub processFile(fil As Scripting.File, rpt As Scripting.TextStream)
    
    Const FUNC_NAME$ = "processFile"
    On Error GoTo errorHandler
    
    Dim filpath As String: filpath = fil.ParentFolder.Path
    Dim filname As String: filname = fil.name
    
    Dim fileSys As FileSystemObject
    Set fileSys = New FileSystemObject
    
    Dim txtfil As Scripting.TextStream
    Set txtfil = openInputText(fil.Path, fileSys)
    
    Dim i As Integer
    If Len(mtxtFilter) = 0 Then
        Dim sExt As String
        i = InStrRev(filname, ".")
        If i > 0 Then
           sExt = Mid$(filname, i + 1)
        Else
           sExt = "-"
        End If
        Call writeRpt(rpt, _
        filpath & vbTab & _
        filname & vbTab & _
        sExt & vbTab & _
        fil.Size & vbTab & _
        fil.DateCreated & vbCrLf)
    Else ' FILTER FOR SPECIFIC TEXT
        Dim l As Long
        Dim s As String
        Do While Not txtfil.AtEndOfStream
            l = l + 1
            s = txtfil.ReadLine
            For i = 0 To mtxtPatCnt - 1
                Dim ss As String
                Dim pt As String
                If noCase Then
                    ss = LCase$(s)
                    pt = LCase$(mtxtPats(i))
                Else
                    ss = s
                    pt = mtxtPats(i)
                End If
                If ss Like pt Then
                    s = Replace(s, vbTab, " ")
                    
                    Call writeRpt(rpt, _
                    filpath & vbTab & _
                    filname & vbTab & _
                    l & vbTab & _
                    s & vbCrLf)
                    
                End If
            Next i
        Loop
    End If
    
errorHandler:

    If Not txtfil Is Nothing Then txtfil.Close
    Set fileSys = Nothing
    Set txtfil = Nothing
    
    If Err Then _
        Err.Raise Err.Number, Description:=TypeName(Me) & "::" & FUNC_NAME$ & " " & _
        vbCrLf & "[" & fil.Path & "]" & _
        vbCrLf & Err.Description
        
End Sub


Public Property Get contentFilter() As String
    contentFilter = mtxtFilter
End Property

Public Property Let contentFilter(ByVal vNewValue As String)
    
    mtxtFilter = vNewValue
    mtxtPats = Split(LCase$(vNewValue), "|")
    mtxtPatCnt = UBound(mtxtPats) + 1
    
End Property
