C# File.Copy 工作记录

来源:互联网 发布:windows 查看端口 编辑:程序博客网 时间:2024/05/19 18:42

工作设计特定文件夹内文件导出到按照规律新建文件夹下

查找到关于Copy的两个方法

第一个:将现有文件复制到新文件。 不允许覆盖同名的文件。

获取要保存的路径,如果没有,建立该路径下文件夹。 然后用

public static void Copy(string sourceFileName,//资源文件名称string destFileName// 要复制到目标文件名称)

 string sFileName = DateTime.Now.ToString("yyyy-MM-dd") +" "+ this.lvPrint.Items[i].SubItems[1].Text.ToString().Trim();

 string savePath = spdd.GetDLLAppKey("savePath") + "\\" + sFileName;
 Directory.CreateDirectory(savePath);
 string path1=getpath(ds.Tables[0].Rows[m]["picname"].ToString());

 File.Copy(path1, Path.Combine(savePath, Path.GetFileName(path1))); //path1是资源文件名称,savePath是保存路劲,需要Path.Combine(savePath, Path.GetFileName(path1)) 组合成目标文件名称字段。然后进行复制。

第二种:将现有文件复制到新文件。 允许覆盖同名的文件。

转自msdn https://msdn.microsoft.com/zh-cn/library/9706cfs5(v=vs.110).aspx

语法

C#
C++
F#
VB
public static void Copy(string sourceFileName,string destFileName,bool overwrite)

参数

sourceFileName
Type: System.String

要复制的文件。

destFileName
Type: System.String

目标文件的名称。 不能是目录。

overwrite
Type: System.Boolean

如果可以覆盖目标文件,则为 true;否则为 false


0 0
原创粉丝点击