Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

List files and folders - SysFileControls


Redim sArray(0) As String
Call DirWalk( "*.*" , "C:\data" , sArray)


Sub DirWalk( ByVal sPattern As String , _
        ByVal CurrDir As String , sFound() _
        As String )
Dim i As Integer
Dim sCurrPath As String
Dim sFile As String
Dim ii As Integer
Dim iFiles As Integer
Dim iLen As Integer

If Right$(CurrDir, 1) <> "\" Then
       Dir1.Path = CurrDir & "\"
Else
       Dir1.Path = CurrDir
End If
For i = 0 To Dir1.ListCount
        If Dir1.List(i) <> "" Then
                DoEvents
                Call DirWalk(sPattern, _
                       Dir1.List(i), sFound())
        Else
                If Right$(Dir1.Path, 1) = "\" _
                        Then
                       sCurrPath = Left(Dir1.Path, _
                               Len(Dir1.Path) - 1)
                Else
                       sCurrPath = Dir1.Path
                End If
               File1.Path = sCurrPath
               File1.Pattern = sPattern
                If File1.ListCount > 0 Then
                        'matching files found In the directory
                        For ii = 0 To File1.ListCount - 1
                                Redim Preserve _
                                       sFound( Ubound (sFound) _
                                        + 1)
                               sFound( Ubound (sFound) - _
                                       1) = sCurrPath & _
                                        "\" & File1.List(ii)
                        Next ii
                End If
               iLen = Len(Dir1.Path)
                Do While Mid (Dir1.Path, iLen, _
                       1) <> "\"
                       iLen = iLen - 1
               Loop
               Dir1.Path = Mid (Dir1.Path, 1, _
                       iLen)
        End If
Next i
End Sub