system.io.directory question

nd54

Member
Joined
May 2, 2003
Messages
8
Location
CA
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
Code:
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
 
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 ...
 
Back
Top