Created
January 14, 2019 10:44
-
-
Save LoriBru/4923a3a9fef779359683de67aa01c5d1 to your computer and use it in GitHub Desktop.
Clone a directory with all its files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void CloneDirectory(string root, string dest) | |
| { | |
| foreach (var directory in Directory.GetDirectories(root)) | |
| { | |
| var dirName = Path.GetFileName(directory); | |
| if (!Directory.Exists(Path.Combine(dest, dirName))) | |
| { | |
| Directory.CreateDirectory(Path.Combine(dest, dirName)); | |
| } | |
| CloneDirectory(directory, Path.Combine(dest, dirName)); | |
| } | |
| foreach (var file in Directory.GetFiles(root)) | |
| { | |
| File.Copy(file, Path.Combine(dest, Path.GetFileName(file))); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment