Reputation: 63
I'm trying copy file from one location to another but when I do it with the Copy function
System.IO.File.Copy(OldFilePath, NewFilePath, true);
The file details like the creation date, modified date, accessed date and etc are not copied with the file. How can I copy the file with the file's details?
Upvotes: 0
Views: 277
Reputation: 1718
Adding the following instructions after the Copy instruction will update some DateTime attributes:
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));
Upvotes: 1