private void MoveDirectory(string sourceDir, string targetDir, bool allowOverWriteFile) { if (targetDir[targetDir.Length - 1] != Path.DirectorySeparatorChar) { targetDir += Path.DirectorySeparatorChar; } if (!Directory.Exists(targetDir)) { Directory.CreateDirectory(targetDir); } string[] files = Directory.GetFileSystemEntries(sourceDir); foreach (string element in files) { // Sub directories if (Directory.Exists(element)) { MoveDirectory(element, Path.Combine(targetDir, Path.GetFileName(element)), allowOverWriteFile); } // Files in directory else { File.Copy(element, Path.Combine(targetDir, Path.GetFileName(element)), allowOverWriteFile); } } }