public FileTree GetSubTree(DirectoryInfo directory) { FileTree tree = SubFileTrees.FirstOrDefault(p => p.Directory?.FullName == directory.FullName); if (tree == null) { FileTree child = new FileTree(directory); SubFileTrees.Add(child); return(child); } else { return(tree); } }
private void InsertToFileTree(FileInfo file) { Stack <DirectoryInfo> directories = new Stack <DirectoryInfo>(); DirectoryInfo directory = new DirectoryInfo(file.FullName); while ((directory = directory.Parent).FullName != task.TargetBackupDirectory) { directories.Push(directory); } FileTree currentTree = tree; while (directories.Count > 0) { directory = directories.Pop(); currentTree = currentTree.GetSubTree(directory); } currentTree.SubFileTrees.Add(new FileTree(file)); }
public FileTree GetFileTree() { SearchFiles(); tree = new FileTree(new DirectoryInfo(task.TargetBackupDirectory)); //foreach (var path in filePaths) //{ // if (realFileInfos.ContainsKey(path)) // { // InsertToFileTree(realFileInfos[path]); // } // else // { // InsertToFileTree(notExistFileInfo[path]); // } //} foreach (var file in realFileInfos) { InsertToFileTree(file.Value); } return(tree.SubFileTrees[0]); }