如何用C#复制指定的几个文件?这个代码怎么写呢??

 我来答
cyou0
推荐于2016-10-28 · TA获得超过1840个赞
知道小有建树答主
回答量:1614
采纳率:0%
帮助的人:886万
展开全部
用这个方法:
Copy(String, String, Boolean) 将现有文件复制到新文件。允许覆盖同名的文件。

已下是例子:

using System;
using System.IO;

class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
string path2 = path + "temp";

try
{
// Create the file and clean up handles.
using (FileStream fs = File.Create(path)) {}

// Ensure that the target does not exist.
File.Delete(path2);

// Copy the file.
File.Copy(path, path2);
Console.WriteLine("{0} copied to {1}", path, path2);

// Try to copy the same file again, which should succeed.
File.Copy(path, path2, true);
Console.WriteLine("The second Copy operation succeeded, which was expected.");
}

catch
{
Console.WriteLine("Double copy is not allowed, which was not expected.");
}
}
}
追问
路径需要是动态获取的。不是指定的路径
追答
那你就动态获取嘛!
lovenorth
2011-12-21 · TA获得超过302个赞
知道小有建树答主
回答量:301
采纳率:0%
帮助的人:135万
展开全部
你可以去收下C# 文件操作类 ,在CSDN或者博客园上有很多文章 实在找不着 联系我我发给你
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式