Hi.
this is a recursive function that search in a specified path.
it returns an arrayList of paths, you can put it in a listbox after.
see that you don't have UnauthorizedAccessException.
calling the function:
Dim results As ArrayList = searchDirectory("c:\", "*.doc")
Private Function searchDirectory(ByVal path As String, ByVal filetype As String) As ArrayList
Dim arr As New ArrayList
Dim dirs As String() = Directory.GetDirectories(path)
Dim dir As String
For Each dir In dirs
arr.AddRange(searchDirectory(dir, filetype))
Next
Dim files As String() = Directory.GetFiles(path, filetype)
Dim file As String
For Each file In files
arr.Add(file)
Next
Return arr
End Function
hope it helps.
|