public static void ReCreateeTree(string rootFolder, FoldersTree folderTree) { foreach (var subFolder in folderTree.SubDirs) { // создаем под директорию var fullNameSubDir = Path.Combine(rootFolder, subFolder.directoryName); if (!Directory.Exists(fullNameSubDir)) { Directory.CreateDirectory(fullNameSubDir); } // для каждой созданной диретории создаем её поддиреторию foreach (var subTree in subFolder.SubDirs) { ReCreateeTree(fullNameSubDir, subTree); } } }
private static FoldersTree generateSubTree(string rootFolder) { var di = new DirectoryInfo(rootFolder); var result = new FoldersTree() { directoryName = di.Name, SubDirs = new List <FoldersTree>() }; foreach (var dir in Directory.GetDirectories(rootFolder)) { // var dirName = Path.Combine(rootFolder, dir); var subTree = generateSubTree(dir); result.SubDirs.Add(subTree); } return(result); }