Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am trying to get all sub directorys, and load them into a treeview. its only getting the first subdirectory. how can I get all of the subdirectories

dim Drive 
dim Drives = Directory.GetLogicalDrives() 
Dim Folder, Folders
For each Drive in Drives
With TreeView1.Nodes.Add(drive)
Folders = Directory.GetDirectories(drive)
For each folder in folders
.nodes.add(folder)
next
end with
next

Posted

If you want populate the tree all at once, I recommend a recursive function to do this... heres some psuedocode:

 

functon addentry(rootnode as node, rootpath as string)

 

get an array of each directory and enter it as a child

in this node (be sure to grab a reference to the node you

created just in case you have to use it when doing a

recursive call)

 

on each child node you add to this 'rootnode' you

can check if the directory you are adding has any sub-

directories.. if it does, have the function call ITSELF

passing the child node and the rootpath + the directory

name added to the end of it... otherwise just exit out of

the function when you are done adding entries

 

end function

 

If you are reading a large drive though, the above article solves

that problem... because populating all at once isnt neccisary unless you really need it :)

 

hope that helped ...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...