VB.net TreeView遍历文件夹和文件夹下所有文件

  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

 

VB.net TreeView遍历文件夹和文件夹下所有文件VB.net TreeView遍历文件夹和文件夹下所有文件 aa326358942 发布了9 篇原创文章 · 获赞 0 · 访问量 4538 私信 关注
上一篇:3、VB网抓高德地图货车路径规划距离(借助刘永富老师插件解析JSON格式数据)


下一篇:.net,C#,Vb,F#,Asp,Asp.net区别以及作用和方向