CSharp examples for File IO:Directory
Copy folder recursive
using System.IO;//from w w w . j av a 2s . c o m using System; public class Main{ public static void Copy(string sourceDirName, string destDirName, bool recursive, bool overwrite) { DirectoryInfo dir = new DirectoryInfo(sourceDirName); DirectoryInfo[] dirs = dir.GetDirectories(); if (!dir.Exists) { throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " + sourceDirName); } if (!Directory.Exists(destDirName)) { Directory.CreateDirectory(destDirName); } FileInfo[] files = dir.GetFiles(); foreach (FileInfo file in files) { file.CopyTo(Path.Combine(destDirName, file.Name), overwrite); } if (recursive) { foreach (DirectoryInfo subdir in dirs) { Copy(subdir.FullName, Path.Combine(destDirName, subdir.Name), recursive, overwrite); } } } }