0

I am wanting to display the PC's System Directory in a treeview. I have been searching for how to do this for some time now without finding anything. if anybody can help me out i would greatly appreciate it.

thanks

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by GeekByChoiCe
1

try this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        treeDir.Nodes.Clear()
        CreateDirTree(Nothing, Environment.SystemDirectory)
    End Sub

    Private Sub CreateDirTree(ByVal fromNode As TreeNode, ByVal basePath As String)
        Dim newDir As TreeNode
        Dim subDir As String

        For Each singleDir As String In My.Computer.FileSystem.GetDirectories(basePath)
            subDir = My.Computer.FileSystem.GetName(singleDir)


            If fromNode Is Nothing Then
                newDir = treeDir.Nodes.Add(subDir)
            Else
                newDir = fromNode.Nodes.Add(subDir)
            End If

            CreateDirTree(newDir, My.Computer.FileSystem.CombinePath(basePath, subDir))
        Next singleDir
    End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.