/// <summary> /// 移除结点 /// </summary> /// <param name="node"></param> public void Remove(BoTree <String> node) { if (nodes.Contains(node)) { nodes.Remove(node); } }
/// <summary> /// 添加结点 /// </summary> /// <param name="node">结点</param> public void AddNode(BoTree <String> node) { if (!nodes.Contains(node)) { node.parent = this; nodes.Add(node); } }
/// <summary> /// 查找结点 /// </summary> /// <param name="nodes">结点集合</param> public List <BoTree <String> > getNode(BoTree <String> parent) { List <BoTree <String> > Nodes = new List <BoTree <String> >(); foreach (var node in parent.Nodes) { Nodes.Add(node); } return(Nodes); }
static void Main(string[] args) { /* * String path1 = @"\\Hcdata\和创施工图设计平台\公建一所\"; * String path2 = @"\\Hcdata\和创施工图设计平台\公建二所\"; * String path3 = @"\\Hcdata\和创施工图设计平台\居住一所\"; * String path4 = @"\\Hcdata\和创施工图设计平台\居住二所\"; * * BoTree<String> fileTree = new BoTree<string>(); * getFile(path1,"", @"E:\公建一所"); * Console.WriteLine("path1 finished"); * getFile(path2, "", @"E:\公建二所"); * Console.WriteLine("path2 finished"); * getFile(path3, "", @"E:\居住一所"); * Console.WriteLine("path3 finished"); * getFile(path4, "", @"E:\居住二所"); * Console.WriteLine("path4 finished"); */ BoTree <String> tree1 = new BoTree <string>(); /* * getFolder(@"\\Hcdata\和创施工图设计平台\", "公建一所", ref tree1); * getFolder(@"\\Hcdata\和创施工图设计平台\", "公建二所", ref tree1); * getFolder(@"\\Hcdata\和创施工图设计平台\", "居住一所", ref tree1); * getFolder(@"\\Hcdata\和创施工图设计平台\", "居住二所", ref tree1); */ Thread[] t = new Thread[4]; t[0] = new Thread(() => getFolder(@"\\Hcdata\和创施工图设计平台\", "公建一所", ref tree1)); t[1] = new Thread(() => getFolder(@"\\Hcdata\和创施工图设计平台\", "公建二所", ref tree1)); t[2] = new Thread(() => getFolder(@"\\Hcdata\和创施工图设计平台\", "居住一所", ref tree1)); t[3] = new Thread(() => getFolder(@"\\Hcdata\和创施工图设计平台\", "居住二所", ref tree1)); foreach (Thread item in t) { item.Start(); } foreach (Thread item in t) { item.Join(); } Console.WriteLine("输入回车结束!"); Console.ReadLine(); }
public static void getFolder(String path, String filter, ref BoTree <String> fileTree) { Console.WriteLine("filter=" + filter + ",path=" + path); if (filter == "20*") { String[] dirs1 = Directory.GetDirectories(path, filter); foreach (String tmp in dirs1) { BoTree <String> tmpTree = new BoTree <String>(); tmpTree.Data = tmp.ToString(); getFolder(tmp, "项师*", ref tmpTree); fileTree.AddNode(tmpTree); } } else if (filter == "项师*") { string[] files1 = Directory.GetFiles(path, "*打分表.xlsx", SearchOption.AllDirectories); System.IO.File.WriteAllLines(@"E:\" + path.Split("\\")[4] + "_" + path.Split("\\")[5] + "评分表信息.txt", files1); //Console.WriteLine("path="+path+ @"E:\" + path.Split("\\")[4]); /* * foreach (String tmp in files1) * { * BoTree<String> tmpTree = new BoTree<String>(); * tmpTree.Data = tmp.ToString(); * fileTree.AddNode(tmpTree); * } */ } else { String[] dirs1 = Directory.GetDirectories(path, filter); // Console.WriteLine("filter=" + filter + ",size=" + dirs1.Length); foreach (String tmp in dirs1) { BoTree <String> tmpTree = new BoTree <String>(); tmpTree.Data = tmp.ToString(); getFolder(tmp, "20*", ref tmpTree); fileTree.AddNode(tmpTree); } } }