Getting file move datetime

纵饮孤独 提交于 2019-12-02 01:45:42

问题


When you copy a file (in a windows environment), the Creation and LastAccess datetime are modified and can be retrieved with a FileInfo object.

However, I can't find any reliable datetime (directly linked to a file) that would be changed when a file is moved into a folder. Does windows update any datetime value in the file when it's moved (and can it be retrieved)?

Note I'm not in a dead end and I have many workarounds. I'm just wondering if this could be handled directly at the file level to avoid unnecessary logic.


回答1:


So this seems to be how this works in Windows:

  • Creation time: if the target file already exists, its' creation time is preserved, otherwise it is set to the current system time.
  • Last Modification time: always copied from modification time of the source file.
  • Last Access time: always set to the current system time.

RoboCopy and RichCopy are couple of command-line tools that can preserve the mtime for directories with the /DCOPY:T switch, but this only works in Vista and newer. Another copy utility which can preserve timestamps is XXCOPY

You can find some example for RoboCopy at the end of this page: http://www.computerhope.com/robocopy.htm




回答2:


How about using FileInfo's LastWriteTime? It looks like it keeps the date from original file



来源:https://stackoverflow.com/questions/21558159/getting-file-move-datetime

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