11

我今天正在调试一些代码,并注意到我的一个FileInfo对象LastWriteTime比它的时间更早CreationTime。这是可能的/预期的吗?

4

4 回答 4

25

These properties of the file can be modified to take any value. So there's absolutely nothing to stop this happening.

That said, the most likely explanation is that the file was copied from one place to another. The creation time will be the time the copy took place. The modification time will be the time the source file was last modified, i.e. before the copy. So, when the file is copied, the modification time is also copied. To see this happen, simply pick a file on your machine. Create a copy of it (CTRL+C, CTRL+V) and look at the properties of the copy.

In other words, it is actually not a contradiction for the creation time to be later than the modification time. The creation time is when this file object was created. The modification time is when the file contents were modified.

于 2012-04-23T09:17:37.987 回答
5

当然可以,只需复制一些文件并将其粘贴到同一个文件夹中,您会看到日期不同: 在此处输入图像描述

于 2012-04-23T09:22:14.977 回答
2

Of course it's possible. Creation and modification time of a file are just metadata and can be changed by anyone who feels like it.

于 2012-04-23T09:18:00.167 回答
2

此方法可能返回不准确的值,因为它使用的本机函数的值可能不会被操作系统持续更新。

http://msdn.microsoft.com/en-us/library/system.io.filesysteminfo.lastwritetime.aspx

于 2012-04-23T09:20:56.023 回答