.Net File.GetLastAccessTime 更新文件的上次访问时间

发布于 2024-12-18 17:09:53 字数 180 浏览 3 评论 0原文

我们使用下面的行来获取文件的上次访问日期和时间。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娜些时光,永不杰束 2024-12-25 17:09:53

您可能会发现这篇文章很有用,特别是:

从 Windows Vista 开始,默认情况下禁用维护上次访问时间

这意味着现在大多数操作系统不会维护上次访问时间(我认为这可以解释您所看到的奇怪行为)。

即使情况并非如此,这篇文章也重点介绍了许多情况中的一些情况,其中最后访问时间可能在您无意时被更新 - 您能否确定您的应用程序不执行任何其他文件访问?

You may find this post useful, in particular:

Starting in Windows Vista, maintaining the last-access time is disabled by default.

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文