在: 如何在 Delphi 中获取文件的创建/最后修改日期?我发现获取创建/上次修改/上次访问日期/时间的联合国文件,但是要在文件中设置此值,我能做什么?非常感谢。
问问题
2960 次
2 回答
15
在单元IOUtils.pas
中,您可以在记录中找到相应的方法TFile
和TDirectory
: SetCreationTime
, SetLastAccesstime
,SetLastWriteTime
并附有它们的 UTC 兄弟。
于 2011-09-26T14:19:16.607 回答
3
尝试SysUtilsSysUtils.FileSetDate
单元中的函数,该单元在内部调用SetFileTime
WinApi 函数。
这个函数有两个版本
function FileSetDate(const FileName: string; Age: Integer): Integer;
function FileSetDate(Handle: THandle; Age: Integer): Integer;
Age 参数是要设置的时间。您必须使用DateTimeToFileDate
将TDateTime值转换为 Windows 操作系统时间戳。
像这样
FileSetDate(FileName, DateTimeToFileDate(Now));
于 2011-09-26T14:15:28.653 回答