Created
November 5, 2016 12:15
-
-
Save zhenlinyang/fe4cd06e8338ab557045968a88f18bbd to your computer and use it in GitHub Desktop.
CopyAndReplaceDirectory
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
private static void CopyAndReplaceDirectory(string srcPath, string dstPath) | |
{ | |
if (Directory.Exists(dstPath)) | |
{ | |
Directory.Delete(dstPath); | |
} | |
if (File.Exists(dstPath)) | |
{ | |
File.Delete(dstPath); | |
} | |
Directory.CreateDirectory(dstPath); | |
foreach (var file in Directory.GetFiles(srcPath)) | |
{ | |
File.Copy(file, Path.Combine(dstPath, Path.GetFileName(file))); | |
} | |
foreach (var dir in Directory.GetDirectories(srcPath)) | |
{ | |
CopyAndReplaceDirectory(dir, Path.Combine(dstPath, Path.GetFileName(dir))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment