Skip to content

Instantly share code, notes, and snippets.

@zhenlinyang
Created November 5, 2016 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhenlinyang/fe4cd06e8338ab557045968a88f18bbd to your computer and use it in GitHub Desktop.
Save zhenlinyang/fe4cd06e8338ab557045968a88f18bbd to your computer and use it in GitHub Desktop.
CopyAndReplaceDirectory
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