列出VB.net中的所有子目录

问题描述:

谁能告诉我如何在vb.net中列出所有子文件夹.我想将其放在列表框中,我创建了一个代码,但是它仅在当前位置搜索,并且不包括子文件夹.这是我的代码,

can anyone tell me how to list all subfolders in vb.net. i want to put it on a listbox, i have created a code but it only search on the current location, and does not include subfolder. here is my code,,

Imports System.IO

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim dnum, fnum As Integer


        For Each drive As String In Directory.GetLogicalDrives()
            ListBox1.Items.Add(drive)
        Next drive

        Do While dnum < ListBox1.Items.Count - 3


            Dim di As New DirectoryInfo(ListBox1.Items(dnum))
            'for every subdirectory in the folder, add its name to the listbox
            For Each subdi As DirectoryInfo In di.GetDirectories
                ListBox2.Items.Add(subdi.Name)
            Next
            dnum = dnum + 1

        Loop

        dnum = 0
        Do While dnum < ListBox1.Items.Count - 2
            fnum = 0
            Do While fnum < ListBox2.Items.Count
                Dim loc As String


                loc = (ListBox1.Items(dnum) + ListBox2.Items(fnum))

                Try
                    Dim di As New DirectoryInfo(loc)
                    'for every subdirectory in the folder, add its name to the listbox
                    For Each subdi As DirectoryInfo In di.GetDirectories
                        ListBox3.Items.Add(subdi.Name)
                    Next
                Catch ex As Exception
                End Try

                fnum = fnum + 1

            Loop
            dnum = dnum + 1
        Loop
    End Sub
End Class