Get all folder / directories list in VB.net

Posted by Henry on Stack Overflow See other posts from Stack Overflow or by Henry
Published on 2010-03-11T19:46:58Z Indexed on 2010/03/11 19:49 UTC
Read the original article Hit count: 314

Filed under:

Hi, this is my first Stackoverflow question, im learning VB and having a few problems with getting a list of all folders/directories on the system, im using the code included here and it seems to work until it hits the recycle bin folder, and some other system folders

Sub main()

    Dim DirList As New ArrayList
    GetDirectories("c:\", DirList)


    For Each item In DirList
        'add item to listbox or text etc here
    Next

End sub

End Sub

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
End Sub

Can anyone help me with this, id like to know what is causing this first, and a good fix, or alternative way to do this.

Thanks in advance.

© Stack Overflow or respective owner

Related posts about vb.net