Introduction
This routine will search a folder and its subfolders and generate a list of
files/folders.
just do something like: RecurseFiles "C:\Windows"
You need List1, a Listbox. or change it to do whatever you want with the names.
Sub RecurseFiles(fPath As String)
Dim File_Name As String
Dim File_Path As String
Dim File_Read As Integer
Dim x As Boolean
Dim i As Integer
File_Path = fPath
If Right$(fPath, 1) <> "\" Then File_Path
= fPath & "\"
File_Name = Dir$(File_Path, vbDirectory)
File_Read = 1
x = False
Do While File_Name <> ""
If File_Name <> "."
And File_Name <> ".." Then
strtpath$
= File_Path & File_Name
x = True
If GetAttr(strtpath)
And vbDirectory Then
' Create a list of files/folders in this subfolder
RecurseFiles strtpath$
Else
' just add the files and subfolders name not the rootname$
' to the list
'ie: "c:\Windows\temp" would be "temp"
List1.AddItem Mid$(strtpath$, Len(Dir1.Path) + 2)
End If
End If
If x = True Then
File_Name
= Dir$(File_Path, vbDirectory)
For i = 2
To File_Read
File_Name = Dir$
Next
x = False
End If
File_Name = Dir$
File_Read = File_Read + 1
Loop
End Sub