Skip to content

Instantly share code, notes, and snippets.

@fresky
Created September 17, 2012 08:17
Show Gist options
  • Save fresky/3736144 to your computer and use it in GitHub Desktop.
Save fresky/3736144 to your computer and use it in GitHub Desktop.
Copy directory in C#
//Now Create all of the directories
foreach (string dirPath in Directory.GetDirectories(SourcePath, "*",
SearchOption.AllDirectories))
Directory.CreateDirectory(dirPath.Replace(SourcePath, DestinationPath));
//Copy all the files
foreach (string newPath in Directory.GetFiles(SourcePath, "*.*",
SearchOption.AllDirectories))
File.Copy(newPath, newPath.Replace(SourcePath, DestinationPath));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment