我想知道如何列出一个文件root
夹中的每个文件夹ListBox
我一直在Google周围搜索,但是我什么都不懂,所以根本没有任何帮助。我当前的代码是
Private Sub ListBox1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' make a reference to a directory
Dim di As New IO.DirectoryInfo("C:\\TTC\projects\")
Dim diar1 As IO.FileInfo() = di.GetFiles()
Dim dra As IO.FileInfo
'list the names of all files in the specified directory
For Each dra In diar1
ListBox1.Items.Add(dra)
Next
End Sub
我使用的进口商品是System.IO
,System.Collections
似乎仍然没有任何效果,有什么想法吗?
编辑:
我制作的脚本正在查找文件而不是文件夹,因此只需将所有内容更改为Directory而不是File
我认为您需要一个递归例程。尝试这样的事情:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ListBox1.Items.Clear()
ListBox1.BeginUpdate()
FillListBox("C:\TTC\projects\")
ListBox1.EndUpdate()
End Sub
Private Sub FillListBox(folder As String)
Dim fi As New IO.DirectoryInfo(folder)
ListBox1.Items.Add(fi.FullName)
For Each f In fi.GetDirectories
FillListBox(f.FullName)
Next
End Sub
End Class
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句