title: Get all the folders and sub-folders in side a directory
body: <p>I am learning VB.net, I would like to know how to get all the folders and sub-folder s inside a directory and how to add them all to a listbox. I would also like it to list the folders while it is scanning like showing the current folders found. I have tried a few things but they never seem to work. I have tried this: </p>
  
  <pre><code>Sub GetDirectories(ByVal StartPath As String, ByRef DirectoryList As ArrayList)
      Dim Dirs() As String = Directory.GetDirectories(StartPath)
      DirectoryList.AddRange(Dirs)
      For Each Dir As String In Dirs
          GetDirectories(Dir, DirectoryList)
      Next
      For Each item In DirectoryList
          ListBox1.Items.Add(item)
      Next
  End Sub
  
  Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      Dim DirList As New ArrayList
      GetDirectories("c:\hexing\", DirList)
  End Sub
  </code></pre>