.NET FileInfo.LastWriteTime & FileInfo.LastAccessTime are wrong

前端 未结 7 983
终归单人心
终归单人心 2020-12-01 13:54

When I call FileInfo(path).LastAccessTime or FileInfo(path).LastWriteTime on a file that is in the process of being written it returns the time tha

相关标签:
7条回答
  • 2020-12-01 15:01

    The FileInfo values are only loaded once and then cached. To get the current value, call Refresh() before getting a property:

    f.Refresh();
    t = f.LastAccessTime;
    

    Another way to get the current value is by using the static methods on the File class:

    t = File.GetLastAccessTime(path);
    
    0 讨论(0)
提交回复
热议问题