Expanding a basic recursive method I got from this news group for getting all
files in a directory and it's subdirectories, I thought someone might be
interested in this (it's pretty simple but works well). The filenames
matching the searchpattern (nothing returns all) are returned in the List
arraylist. Note that the searchpattern should be input in lower case to be
sure it works with all option compares. If returnpath is true, the full path
and filename are returned. If chksubdir is true, files in the subdirectory
are returned as well.
Just thought someone new to VB might be interested.
Private Sub ListFiles(ByRef list As ArrayList, ByVal sPath As String, ByVal
searchpattern As String, ByVal returnpath As Boolean, ByVal chksubdir As
Boolean)
Dim di As System.IO.DirectoryInfo
Try
di = New System.IO.DirectoryInfo(sPath)
For Each fi As System.IO.FileInfo In di.GetFiles
If fi.Name.ToLower Like searchpattern OrElse searchpattern =
Nothing Then
If returnpath Then list.Add(fi.FullName) Else
list.Add(fi.Name)
End If
Next
If chksubdir Then
For Each diSub As System.IO.DirectoryInfo In di.GetDirectories
ListFiles(list, diSub.FullName, searchpattern,
returnpath, chksubdir)
Next
End If
Catch ex As Exception
list = Nothing
errmsg = ex.Message
errno = Err.Number
End Try
End Sub
--
Dennis in Houston