recursive for folder path
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TreeView1.Nodes.Clear()
BuildDirectoryTree(Nothing, "D:\RecursiveTreeview")
TreeView1.ExpandAll()
End Sub
Private Sub BuildDirectoryTree(ByVal fromNode As TreeNode, ByVal basePath As String)
Dim newDirectory As TreeNode
Dim justTheSubdirectory As String
For Each oneDirectory As String In My.Computer.FileSystem.GetDirectories(basePath)
justTheSubdirectory = My.Computer.FileSystem.GetName(oneDirectory)
If (fromNode Is Nothing) Then
newDirectory = TreeView1.Nodes.Add(justTheSubdirectory)
Else
newDirectory = fromNode.Nodes.Add(justTheSubdirectory)
End If
BuildDirectoryTree(newDirectory, My.Computer.FileSystem.CombinePath(basePath, justTheSubdirectory))
Next oneDirectory
End Sub
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言