private static void TraverseRootFolderDfs(Folder folder) { Console.WriteLine("Folder name: {0}", folder.Name); var files = folder.Files; foreach (var file in files) { Console.WriteLine("File name {0}", file.Name); } var subfolders = folder.ChildFolders; foreach (var subfolder in subfolders) { TraverseRootFolderDfs(subfolder); } }
private static void TraverseDirectoryDfs(DirectoryInfo directory, Folder folder) { var files = directory.GetFiles(); foreach (var file in files) { var fileToAdd = new File(file.Name, file.Length); folder.Files.Add(fileToAdd); } var directories = directory.GetDirectories(); foreach (var dir in directories) { var newFolderToAdd = new Folder(dir.Name); TraverseDirectoryDfs(dir, newFolderToAdd); folder.ChildFolders.Add(newFolderToAdd); } }