File.GetLastWriteTime似乎回到“过时”的价值 [英] File.GetLastWriteTime seems to be returning 'out of date' value

查看:867
本文介绍了File.GetLastWriteTime似乎回到“过时”的价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个工具来收集工具的用户指定的时间窗口内的日志文件。直至现在,我通过使用上的日志文件的File.GetLastWriteTime方法,这种比较用户输入的时间,并根据这些comparisions的结果收集基础日志文件的集合。这里是一个小code片断:

I have written a tool to collect log files within a time window specified by the user of the tool. Up until now I was basing the collection of log files by using the File.GetLastWriteTime method on the log files, comparing this to the times the user entered and collecting based on the outcome of these comparisions. Here is a small code snippet:

DateTime logFileEnd = File.GetLastWriteTime(matchingActiveLogFile);

不过,我发现我的工具剪掉收集我认为它应该做的一些日志文件。看来此方法返回一个DateTime是过时的,(有文件于这个日期的价值在最近的记录)。

However I noticed my tool didnt collect some log files I thought it should have done. It seems the DateTime returned by this method was out of date, (there was more recent logging in the file than the value of this datetime).

当我看着有问题的文件的修改日期,它也被'过时',还有更近的文件比修改日期的记录。

When I looked at the 'Date Modified' of the file in question, it too was 'out of date', there was more recent logging in the file than the 'Date Modified'.

我如何,我可以得到一个准确的GetLastWriteTime'或修改日期的价值?

How I can I get an accurate 'GetLastWriteTime' or Date Modified value?

推荐答案

在我的expirience我去扔了几个像你这样的问题。在WindowsVist​​a中/ 7系统,该功能的不总是的返回结果可靠。

During my expirience I went throw a couple of issues like yours. On WindowsVista/7 systems that function not always returns a reliable result.

一段时间后,我们发现此链接:<一个href=\"http://blogs.technet.com/b/filecab/archive/2006/11/07/disabling-last-access-time-in-windows-vista-to-improve-ntfs-performance.aspx\"相对=nofollow>在Windows Vista中禁用上次访问时间,提高NTFS的性能

After a while we found this link: Disabling Last Access Time in Windows Vista to improve NTFS performance

和理解,它的无法的是一个强有力的钥匙。要解决这个问题,我们只停留在转发

and understand that it can not be a "strong key". To resolve that issue, we just stop relaying on

GetLastWriteTime

呼叫,但最后存储改变值的文件或者在它的名字,如FileName_yyyymmdd,或在某些领域该文件内。

call, but store last changed value of the file or in its name, like "FileName_yyyymmdd", or inside that file in some field.

有是另一种解决方案的 GetLastAccessTime 的可以在这里找到:

There is another solution for GetLastAccessTime can find here:

<一个href=\"http://stackoverflow.com/questions/1448716/net-fileinfo-lastwritetime-fileinfo-lastaccesstime-are-wrong\">.NET FileInfo.LastWriteTime&安培; FileInfo.LastAccessTime错了,可能是你的情况太有用了。

.NET FileInfo.LastWriteTime & FileInfo.LastAccessTime are wrong, could be useful in your case too.

我对这个普遍的观点是:不要继电器上的参数,但在创造你的架构别的东西。

My general opinion on this would be: do not relay on that parameter, but invent something else in your architecture.

好运气

这篇关于File.GetLastWriteTime似乎回到“过时”的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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