.NET FileInfo.LastWriteTime和放大器; FileInfo.LastAccessTime是错误的 [英] .NET FileInfo.LastWriteTime & FileInfo.LastAccessTime are wrong

查看:272
本文介绍了.NET FileInfo.LastWriteTime和放大器; FileInfo.LastAccessTime是错误的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我称之为的FileInfo(路径).LastAccessTime 的FileInfo(路径).LastWriteTime 上的文件是在被写入返回该文件被创建,而不是最后一次被写入(即现在)的时间过程。

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 that the file was created, not the last time it was written to (ie. now).

有没有一种方式来获得这些信息?

Is there a way to get this information?

编辑:所有的答复为止。我没试过刷新()但是,这并不做任何。我返回的文件开始到写入时间。这同样适用于静态方法,并创建的FileInfo 的新实例。

To all the responses so far. I hadn't tried Refresh() but that does not do it either. I am returned the time that the file was started to be written to. The same goes for the static method, and creating a new instance of FileInfo.

Codymanix可能有答案,但我没有运行Windows Server(使用Windows 7),我不知道该设置是测试。

Codymanix might have the answer, but I'm not running Windows Server (using Windows 7), and I don't know where the setting is to test.

修改2:没有人发现它有趣的是,这个功能似乎并没有正常工作

Edit 2: Nobody finds it interesting that this function doesn't seem to work?

推荐答案

的FileInfo 值只加载一次,然后缓存。为了得到当前值,调用刷新()获取属性之前:

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;

另一种方式来获得的电流值是通过使用静态方法文件类:

t = File.GetLastAccessTime(path);

这篇关于.NET FileInfo.LastWriteTime和放大器; FileInfo.LastAccessTime是错误的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆