Imports System.IO
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim strFileList(-1) As String
Call GetAllFiles("C:\", "*.*", strFileList)
ListBox1.ClearSelected()
For Each s As String In strFileList
ListBox1.Items.Add(s)
Next s
End Sub
Public Sub GetAllFiles(folder As String, searchPattern As String, ByRef fileList() As String)
'First add all files in the current folder
Dim strFiles(-1) As String
Try
strFiles = Directory.GetFiles(folder, searchPattern, SearchOption.TopDirectoryOnly)
Catch ex As Exception
End Try
If strFiles.GetUpperBound(0) >= 0 Then
Dim intStartIndex As Integer = fileList.GetUpperBound(0) + 1
ReDim Preserve fileList(fileList.GetUpperBound(0) + strFiles.GetUpperBound(0) + 1)
For i As Integer = 0 To strFiles.GetUpperBound(0)
fileList(intStartIndex + i) = strFiles(i)
Next i
End If
'Next go through all folders
Dim strFolders(-1) As String
Try
strFolders = Directory.GetDirectories(folder, "*.*", SearchOption.TopDirectoryOnly)
Catch ex As Exception
End Try
If strFolders.GetUpperBound(0) >= 0 Then
For Each strFolder As String In strFolders
Call GetAllFiles(strFolder, searchPattern, fileList)
Next strFolder
End If
End Sub
End Class