Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy Folder/File without modifying attributes?

Is it possible to copy a file or a folder from one location to another without modifying its attribute data? For example if I have a folder on a network drive and it was created on 2/3/2007 and I want to copy it to my c: drive .. but leave the date/time stamp as 2/3/2007...is that possible?


2 Answers

I'm not sure if it is possible; however you can use the methods within System.IO.File and System.IO.Directory to reset these attributes back to what they were originally.

Specifically the SetCreationTime and SetModificationTime methods will be of most value to you in this case.

like image 182
Nate Avatar answered Mar 02 '26 08:03

Nate


I did something as shown below:

 File.SetCreationTime(tgtFile, File.GetCreationTime(srcFile));
 File.SetLastAccessTime(tgtFile, File.GetLastAccessTime(srcFile));
 File.SetLastWriteTime(tgtFile, File.GetLastWriteTime(srcFile));

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!