Copy Folder/File wiithout modifying attributes?

那年仲夏 提交于 2019-12-18 07:06:32

问题


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?


回答1:


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.




回答2:


I did something as shown below:

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



回答3:


When you copy a file, it will retain the modified date, however the created date will be changed. I doubt there will be an easy way to retain the created date.



来源:https://stackoverflow.com/questions/1050813/copy-folder-file-wiithout-modifying-attributes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!