[cpp]/*
* A recursive method to populate a TreeView
* Author: Danny Battison
* Contact:
gabehabe@googlemail.com
*/
///
/// A method to populate a TreeView with directories, subdirectories, etc
///
/// The path of the directory
/// The "master" node, to populate
public void PopulateTree(string dir, TreeNode node) {
// get the information of the directory
DirectoryInfo directory = new DirectoryInfo(dir);
// loop through each subdirectory
foreach(DirectoryInfo d in directory.GetDirectories()) {
// create a new node
TreeNode t = new TreeNode(d.Name);
// populate the new node recursively
PopulateTree(d.FullName, t);
node.Nodes.Add(t); // add the node to the "master" node
}
// lastly, loop through each file in the directory, and add these as nodes
foreach(FileInfo f in directory.GetFiles()) {
// create a new node
TreeNode t = new TreeNode(f.Name);
// add it to the "master"
node.Nodes.Add(t);
}
}
[/cpp]