public static void CopyEntireDir(string sourcePath, string destPath)
{
//Now Create all of the directories
foreach (string dirPath in Directory.GetDirectories(sourcePath, "*",
SearchOption.AllDirectories))
Directory.CreateDirectory(dirPath.Replace(sourcePath, destPath));
//Copy all the files & Replaces any files with the same name
foreach (string newPath in Directory.GetFiles(sourcePath, "*.*",
SearchOption.AllDirectories))
File.Copy(newPath, newPath.Replace(sourcePath, destPath), true);
}
第一个参数为需要复制的文件夹路径,第二个参数为移动到的文件夹路径
本文介绍了一个用于完全复制文件夹的方法,包括所有子目录和文件。通过遍历源目录及其所有子目录并创建相应的目标目录,然后复制每个文件到新的位置,并在遇到同名文件时进行覆盖。
242

被折叠的 条评论
为什么被折叠?



