如何在C#中复制文件及其详细信息?

时间:2015-08-03 13:25:45

标签: c# file copy file-copying

我尝试将文件从一个位置复制到另一个位置,但是当我使用复制功能执行此操作时

System.IO.File.Copy(OldFilePath, NewFilePath, true);

创建日期,修改日期,访问日期等文件详细信息不会随文件一起复制。 如何使用文件的详细信息复制文件?

1 个答案:

答案 0 :(得分:1)

在Copy指令后添加以下指令将更新一些DateTime属性:

System.IO.File.SetCreationTime  (NewFilePath, System.IO.File.GetCreationTime  (OldFilePath));
System.IO.File.SetLastAccessTime(NewFilePath, System.IO.File.GetLastAccessTime(OldFilePath));
System.IO.File.SetLastWriteTime (NewFilePath, System.IO.File.GetLastWriteTime (OldFilePath));