/// <summary> /// 递归拷贝所有子目录。 /// </summary> /// <param >源目录</param> /// <param >目的目录</param> public static void copyDirectory(string sPath, string dPath) { string[] directories = System.IO.Directory.GetDirectories(sPath); if (!System.IO.Directory.Exists(dPath)) System.IO.Directory.CreateDirectory(dPath); System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(sPath); System.IO.DirectoryInfo[] dirs = dir.GetDirectories(); CopyFile(dir, dPath); if (dirs.Length > 0) { foreach (System.IO.DirectoryInfo temDirectoryInfo in dirs) { string sourceDirectoryFullName = temDirectoryInfo.FullName; string destDirectoryFullName = sourceDirectoryFullName.Replace(sPath, dPath); if (!System.IO.Directory.Exists(destDirectoryFullName)) { System.IO.Directory.CreateDirectory(destDirectoryFullName); } CopyFile(temDirectoryInfo, destDirectoryFullName); copyDirectory(sourceDirectoryFullName, destDirectoryFullName); } } } /// <summary> /// 拷贝目录下的所有文件到目的目录。 /// </summary> /// <param >源路径</param> /// <param >目的路径</param> public static void CopyFile(System.IO.DirectoryInfo path, string desPath) { string sourcePath = path.FullName; System.IO.FileInfo[] files = path.GetFiles(); foreach (System.IO.FileInfo file in files) { string sourceFileFullName = file.FullName; string destFileFullName = sourceFileFullName.Replace(sourcePath, desPath); file.CopyTo(destFileFullName, true); } }