private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs)
{
var 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);
}
foreach (FileInfo file in dir.GetFiles())
{
string temppath = Path.Combine(destDirName, file.Name);
file.CopyTo(temppath, false);
}
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
string temppath = Path.Combine(destDirName, subdir.Name);
DirectoryCopy(subdir.FullName, temppath, copySubDirs);
}
}
}