copy folder c# code example

Example 1: c# copy file

File.Copy(Path.Combine(sourceDir, fName), Path.Combine(distDir, fName));

Example 2: copy-the-entire-contents-of-a-directory-in-c-sharp

//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 & Replaces any files with the same name
foreach (string newPath in Directory.GetFiles(SourcePath, "*.*", 
    SearchOption.AllDirectories))
    File.Copy(newPath, newPath.Replace(SourcePath, DestinationPath), true);