/// <summary> /// Creates a File System node with a given path /// </summary> /// <param name="path">Path that this node represents</param> /// <param name="depth">Integer represnting how deep in the hierarchy this node is</param> public FileSystemNode(string path, FileSystemNode parent) { //fill in the relevant details fullPath = path; this.parent = parent; //get the icon GenerateNodeDisplayDetails(); }
/// <summary> /// Populates this node as a root node representing "My Computer" /// </summary> private void GenerateRootNode() { // if we have data, we can't become a root node. if (children != null) return; //get the display name of the first logical drive fullPath = ""; this.parent = null; //get our drives string[] drives = Environment.GetLogicalDrives(); //create space for the children children = new FileSystemNode[drives.Length]; for (int i = 0; i < drives.Length; i++) { //create the child value children[i] = new FileSystemNode(drives[i], this); } //get the icon GenerateNodeDisplayDetails(); }
/// <summary> /// Updates the contents of this node. /// </summary> public void UpdateNode() { try { //if we have not allocated our children yet if (children == null) { //get sub-folders for this folder Array subFolders = System.IO.Directory.GetDirectories(fullPath); //create space for the children children = new FileSystemNode[subFolders.Length]; for (int i = 0; i < subFolders.Length; i++) { //create the child value children[i] = new FileSystemNode(subFolders.GetValue(i).ToString(), this); } } } /** * This is just a sample, so has bad error handling ;) * **/ catch (System.Exception ioex) { //write a message to stderr System.Console.Error.WriteLine(ioex.Message); } }