c# 复制文件夹内所有文件到另外一个文件夹
/// <summary> /// 将一个文件夹下的所有东西复制到另一个文件夹 /// </summary> public static void CopyDireToDire(string sourceDir, string destDir) { DirectoryInfo sourceDireInfo = new DirectoryInfo(sourceDir); List<FileInfo> fileList = new List<FileInfo>(); GetFileList(sourceDireInfo, fileList); List<DirectoryInfo> dirList = new List<DirectoryInfo>(); GetDirList(sourceDireInfo, dirList); foreach (DirectoryInfo dir in dirList) { string m = dir.FullName; string n = m.Replace(sourceDir, destDir); if (!Directory.Exists(n)) { Directory.CreateDirectory(n); } } foreach (FileInfo fileInfo in fileList) { string m = fileInfo.FullName; string n = m.Replace(sourceDir, destDir); File.Copy(m, n, true); } } private static void GetFileList(DirectoryInfo dir, List<FileInfo> fileList) { fileList.AddRange(dir.GetFiles()); foreach (DirectoryInfo directory in dir.GetDirectories()) GetFileList(directory, fileList); } private static void GetDirList(DirectoryInfo dir, List<DirectoryInfo> dirList) { dirList.AddRange(dir.GetDirectories()); foreach (DirectoryInfo directory in dir.GetDirectories()) GetDirList(directory, dirList); }