public bool ExportFolderAndItsFiles(string sourceFolder, string destFolder)
{
try
{
// string folderName = System.IO.Path.GetFileName(sourceFolder);
// string destfolderdir = System.IO.Path.Combine(destFolder, folderName);
string[] allfiles = System.IO.Directory.GetFiles(sourceFolder);
if (allfiles == null)
{
Console.WriteLine("There is no files in the sourceFolder!");
return false;
}
foreach (string file in allfiles)// 遍历所有文件
{
string filename = Path.GetFileName(file);//得到文件名 ,不带路径的
string destname = Path.Combine(destFolder,filename);//拼接出目的地文件名
File.Copy(file, destname);
}
return true;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return false;
}
}
还不知道这个能不能干活,发出来准备自己做测试
经过测试:可以干活,可以复制所有的文件。
该博客介绍了一个C#函数,用于批量复制指定源文件夹及其包含的所有文件到目标文件夹。通过遍历源文件夹并使用File.Copy方法,成功实现了文件的复制,经测试功能正常。
2197

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



