Delphi覆盖文件和错误的修改日期时间 [英] Delphi overwrite file and wrong modified date time
问题描述
我想在Delphi中获取文件上次修改的时间.
I'd like to get a file last modified time in Delphi.
通常会用FileAge()
之类的方法解决问题,唯一的问题是:如果我用文件B 覆盖 * 文件A *使用CopyFile
,文件A的修改日期不会按照当前的覆盖时间更新(应该)(?)
Normally something like FileAge()
would do the trick, only the problem is: if I overwrite *File A* with File B using CopyFile
, File A's modified date is not updated with current overwrite time as it should(?)
我知道:CopyFile
也复制文件属性,但是我确实需要获取文件被覆盖时也起作用的修改日期.
I get that: CopyFile
also copy file attributes, but I really need to get the modified date that also works when a file is overwritten.
有这样的功能吗?整个应用程序都需要依靠修改时间来决定是否应该继续处理文件!
Is there such function? My whole application relies on modification time to decide whether or not I should proceed with files!
编辑:澄清一下:我仅监视文件.不是我的应用程序正在修改它们.
EDIT Just to clarify: I'm only monitoring the files. It's not my application who's modifying them.
推荐答案
CopyFile
说:
将现有文件的文件属性复制到新文件中.
File attributes for the existing file are copied to the new file.
这意味着您不能基于文件的最后修改属性或文件的任何属性使用程序.确实,有各种各样的方法可以更改文件的最后修改属性.实际上,它可以在时间上倒退.
Which means that you cannot use base your program on the last modified attribute of the file, or indeed any attribute of the file. Indeed there are all sorts of ways for the last modified attribute of the file to change. It can in fact go backwards in time.
相反,我建议您使用 ReadDirectoryChangesW
跟踪修改.这样一来,只要文件被修改,您就可以收到通知.您可以基于ReadDirectoryChangesW
API以基于事件的方式编写程序.
Instead I suggest that you use ReadDirectoryChangesW
to keep track of modifications. That will allow you to receive notifications whenever a file is modified. You can write your program in an event based manner based on the ReadDirectoryChangesW
API.
如果您不能使用ReadDirectoryChangesW
和文件属性,则必须根据文件内容决定.
If you can't use ReadDirectoryChangesW
and the file attributes, then you'll have to base your decisions on the contents of the file.
这篇关于Delphi覆盖文件和错误的修改日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!