Unicode Controls & Classes for VB6 - Version 4

clsSearchFilesAL Class

A very powerful class used to search files; supports asynchronous mode and recursion on subdirectories.
Returns a [cArrayList] class of [clsSearchFilesFInfoAL] classes that you can use to get a lot of file information. Supports UNICODE and UNC paths.

Name Description
eSearchFilesWhat Search flag
Name Description
ItemFound Raised if the [RaiseEvents] is True for every item found during the search
Name Type Description
RaiseEvents (Boolean) Gets or sets the ability to receive events from this class
Name Type Description
CountedFiles (Long) Returns the number of files found during the search (in Async mode)
CurrentDir (String) Returns the current directory when searching (in Async mode)
GetFileDate Returns Datetime info about a specified file
HasBeenStopped (Boolean) Returns True if the searching has finished as a result of a StopSearch function
IsSearching (Boolean) Returns true if the searching process is running (in Async mode)
SearchFilePatternPathNoPatternAL (cArrayList) Searches for files matching a certain pattern into the passed folder and subfolders; the pattern is only applied on files
Returns a cArrayList of [clsSearchFilesFInfo] objects
SearchInPathAL (cArrayList) Searches in the specified path for every file/folder contained; returns a cArrayList of [clsSearchFilesFInfo] objects
SearchPathPatternAL (cArrayList) Searches in the specified folder for a certain pattern; the pattern is applied to files and folders
Returns a cArrayList of [clsSearchFilesFInfo] objects
SortResultsAL Sort the resulting ArrayList ascending or descending
StopSearch Stops the search (in Async mode)
How to use the class:
1- Create an instance of the class and an empty collection
Dim osf As clsSearchFiles
Set osf = New clsSearchFiles
Dim oc As Collection

2- Assign the collection to the class
Set oc=osf.SearchInPath(...)

3- Browse results
Dim osfi As clsSearchFilesFInfo
For i = 1 To oc.Count
Set osfi = oc.Item(i)
'Use the osfi class here ;-)

This sample uses the class for searching files; at the end it sorts them
Draw a ctlUniLabelXP control on the form and paste the code below
Option Explicit

'Uses events
Private WithEvents moSearchSF As clsSearchFilesAL

Private Sub Form_Click()

Dim osfi As clsSearchFilesFInfoAL
Dim ar As cArrayList

Dim sPattern As String
sPattern = "*.*"

Dim i As Long
Dim s As String

'Search files
Set ar = moSearchSF.SearchFilePatternPathNoPatternAL("c:\*.*", esfw_only_files, True, True)

'Sort results Ascending
moSearchSF.SortResultsAL ar, True

'Manage results
MsgBox "Passed from " & moSearchSF.CountedFiles & " files..."

End Sub

Private Sub Form_Load()
Set moSearchSF = New clsSearchFilesAL
moSearchSF.RaiseEvents = True

MsgBox "Click on the form to start the search, close the form to Stop"
End Sub

Private Sub Form_Unload(Cancel As Integer)

If moSearchSF.IsSearching() Then
Cancel = 1
MsgBox "The search has been stopped"
End If

End Sub

Private Sub moSearchSF_ItemFound(osfi As clsSearchFilesFInfoAL)
ctlUniLabelXP1.Caption = "Searching on: " & moSearchSF.CurrentDir
End Sub