列出VB.net中的所有子目录 [英] Listing all sub directories in VB.net
本文介绍了列出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
推荐答案
使用 或实例方法, 这篇关于列出VB.net中的所有子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! Directory.GetDirectories()
静态方法(
Dim di As New DirectoryInfo(Loc)
di.GetDirectories("search", SearchOption.AllDirectories)
查看全文