public DirectoryOrFile() { _name = ""; _path = ""; _parent = null; _sub = new List <DirectoryOrFile>(); _dof_type = DOF_Type.UNDEF; }
public void Set(string name, string path, DirectoryOrFile parent, DOF_Type nodeType) { _name = name; _path = path + "\\" + name; _parent = parent; _sub = new List <DirectoryOrFile>(); _dof_type = nodeType; }
protected void LoadDirTree(ref DirectoryOrFile node, string path, DirectoryOrFile parent, DirectoryOrFile.DOF_Type dofType) { if (node == null) { return; } string nodeName = path.Substring(path.LastIndexOf("\\") + 1); node.Set(nodeName, path, parent, dofType); if (dofType == DirectoryOrFile.DOF_Type.DIR) { //scan for directories try { List <string> dirList = new List <string> (Directory.EnumerateDirectories(path)); foreach (var dir in dirList) { string foo = dir.Substring(dir.LastIndexOf("\\") + 1); Console.WriteLine("{0}", dir.Substring(dir.LastIndexOf("\\") + 1)); DirectoryOrFile sub = new DirectoryOrFile(); LoadDirTree(ref sub, dir, node, DirectoryOrFile.DOF_Type.DIR); node.AddChild(sub); } int num = dirList.Count; Console.WriteLine("{0} directories found.", dirList.Count); } catch (UnauthorizedAccessException UAEx) { Console.WriteLine(UAEx.Message); } catch (PathTooLongException PathEx) { Console.WriteLine(PathEx.Message); } //scan for files try { List <string> fileList = new List <string> (Directory.EnumerateFiles(path)); foreach (var fname in fileList) { string foo = fname.Substring(fname.LastIndexOf("\\") + 1); Console.WriteLine("{0}", fname.Substring(fname.LastIndexOf("\\") + 1)); DirectoryOrFile sub = new DirectoryOrFile(); LoadDirTree(ref sub, fname, node, DirectoryOrFile.DOF_Type.FILE); node.AddChild(sub); } int num = fileList.Count; Console.WriteLine("{0} directories found.", fileList.Count); } catch (UnauthorizedAccessException UAEx) { Console.WriteLine(UAEx.Message); } catch (PathTooLongException PathEx) { Console.WriteLine(PathEx.Message); } } }
protected void OnJobDirChanged(object sender, EventArgs e) { string sendertext = sender.ToString(); string thisString = this.JobDir_textview.Buffer.Text; bool bDirExists = false; try { if (Directory.Exists(this.JobDir_textview.Buffer.Text)) { bDirExists = true; } else { bDirExists = false; } } catch (Exception exp) { Exception foo = exp; }; if (bDirExists) { _jobDir = this.JobDir_textview.Buffer.Text; _jobRoot = new DirectoryOrFile(); LoadDirTree(ref _jobRoot, _jobDir, null, DirectoryOrFile.DOF_Type.DIR); EnableButtons(); TreeStore store = new TreeStore(typeof(string)); this.DataTransfer_treeview.Model = store; TraverseDirTree(_jobRoot, 0, ref store, TreeIter.Zero); this.DataTransfer_treeview.ExpandAll(); } else { DisableButtons(); } }
protected void TraverseDirTree(DirectoryOrFile node, int level, ref TreeStore store, TreeIter iter) { TreeIter thisNodeIter = new TreeIter( ); if (iter.Equals(TreeIter.Zero)) { thisNodeIter = store.AppendValues(node.Name()); } else { thisNodeIter = store.AppendValues(iter, node.Name()); } for (int i = 0; i < level; i++) { Console.Write(" "); } Console.WriteLine("{0} = {1} ({2})", node.Name(), node.Path(), node.Type() == DirectoryOrFile.DOF_Type.DIR ? "D" : (node.Type() == DirectoryOrFile.DOF_Type.FILE ? "F" : "U")); for (int i = 0; i < node.NumChildren(); i++) { TraverseDirTree(node.Child(i), level + 1, ref store, thisNodeIter); } }
public void AddChild(DirectoryOrFile sub) { _sub.Add(sub); }