.Net File.GetLastAccessTime 更新文件的上次访问时间
我们使用下面的行来获取文件的上次访问日期和时间。
DateTime dtLastAccesstime = File.GetLastAccessTime(sFilePath);
但我们面临着奇怪的问题,上面的调用本身修改了最后访问时间。因此,我们有效地将当前时间作为上次访问时间。
We are using below line to get Last access date and time of the file.
DateTime dtLastAccesstime = File.GetLastAccessTime(sFilePath);
But we are facing strange problem, the above call itself modifies the Last access time. So effectively we are getting current time as last access time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能会发现这篇文章很有用,特别是:
这意味着现在大多数操作系统不会维护上次访问时间(我认为这可以解释您所看到的奇怪行为)。
即使情况并非如此,这篇文章也重点介绍了许多情况中的一些情况,其中最后访问时间可能在您无意时被更新 - 您能否确定您的应用程序不执行任何其他文件访问?
You may find this post useful, in particular:
Which means that nowadays most operating systems won't maintain the last access time (which I suppose could account for the odd behaviour you are seeing).
Even if this is not the case this post highlights some of the many scenarios whereby the last access time could have been updated when you didn't mean to - can you be sure that your application doesn't perform any other file access?