Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
createTree(TreeView1, Application.StartupPath)
End Sub
Public Shared Function createTree(ByVal tree As TreeView, ByVal dirname As String) As Boolean
Dim root As TreeNode
root = getRootNode(dirname)
If root Is Nothing Then Return False
tree.Nodes.Add(root)
Return True
End Function
Private Shared Function getRootNode(ByVal dirname As String) As TreeNode
Dim node As TreeNode = New TreeNode(dirname)
Dim dirs As String() = Directory.GetDirectories(dirname)
Dim files As String() = Directory.GetFiles(dirname)
For Each dir As String In dirs
node.Nodes.Add(getRootNode(dir))
Next
For Each file As String In files
If Path.GetExtension(file) = ".flac" OrElse Path.GetExtension(file) = ".mp3" Then
Dim fnode As TreeNode = New TreeNode(Path.GetFileName(file))
node.Nodes.Add(fnode)
End If
Next
Return node
End Function
aa326358942 发布了9 篇原创文章 · 获赞 0 · 访问量 4538 私信 关注