Copy Folder/File wiithout modifying attributes?

前端 未结 3 1670
余生分开走
余生分开走 2020-12-20 03:24

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 cre

相关标签:
3条回答
  • 2020-12-20 04:06

    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.

    0 讨论(0)
  • 2020-12-20 04:16

    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.

    0 讨论(0)
  • 2020-12-20 04:17

    I did something as shown below:

     File.SetCreationTime(tgtFile, File.GetCreationTime(srcFile));
     File.SetLastAccessTime(tgtFile, File.GetLastAccessTime(srcFile));
     File.SetLastWriteTime(tgtFile, File.GetLastWriteTime(srcFile));
    
    0 讨论(0)
提交回复
热议问题