誰能告訴我如何列出vb.net中的所有子文件夾。 我想把它放在一個列表框中,我已經創建了一個代碼,但它只在當前位置上搜索,並且不包含子文件夾。這裏是我的代碼,,列出VB.net中的所有子目錄
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
我應該在搜索模式中放什麼?在「搜索」上 –
使用通配符字符*。*或*或C *等。 – adatapost
在驅動器上使用時總是崩潰。嘗試一下。 –