private static void OutputTreeView(TreeView TreeviewNode, IEnumerable <string> UniqueFilesPath, char PathSeparator) { TreeNode LastNode = null; foreach (string PathToFile in UniqueFilesPath) { string SubPathAgg = string.Empty; foreach (string SubPath in PathToFile.Split(PathSeparator)) { SubPathAgg += SubPath + PathSeparator; TreeNode[] Nodes = TreeviewNode.Nodes.Find(SubPathAgg, true); if (Nodes.Length == 0) { if (LastNode == null) { TreeviewNode.Invoke(new Action(() => LastNode = TreeviewNode.Nodes.Add(SubPathAgg, SubPath)));; } else { TreeviewNode.Invoke(new Action(() => LastNode = LastNode.Nodes.Add(SubPathAgg, SubPath))); } } else { LastNode = Nodes[0]; } } } }
private List <string> GetFiles(string path, string pattern) { var prev = 0; var files = new List <string>(); char PathSeparator = '\\'; try { files.AddRange(Directory.GetFiles(path, pattern, SearchOption.TopDirectoryOnly)); filesFound += files.Count; foreach (var directory in Directory.GetDirectories(path)) { _manualEvent.WaitOne(); files.AddRange(GetFiles(directory, pattern)); Action b = () => textBox4.Text = filesFound.ToString(); if (InvokeRequired) { Invoke(b); } else { b(); } Action c = () => textBox3.Text = directory.ToString(); if (InvokeRequired) { Invoke(c); } if (files.Count > 0) { TreeNode LastNode = null; foreach (string PathToFile in files) { string SubPathAgg = string.Empty; foreach (string SubPath in PathToFile.Split(PathSeparator)) { SubPathAgg += SubPath + PathSeparator; TreeNode[] Nodes = treeView1.Nodes.Find(SubPathAgg, true); if (Nodes.Length == 0) { if (LastNode == null) { Action action = () => LastNode = treeView1.Nodes.Add(SubPathAgg, SubPath); if (InvokeRequired) { Invoke(action); } else { action(); } } else { Action action = () => LastNode = LastNode.Nodes.Add(SubPathAgg, SubPath); if (InvokeRequired) { Invoke(action); } else { action(); } } } else { LastNode = Nodes[0]; } } } } } } catch (UnauthorizedAccessException) { } return(files); }