Delphi 获取上一次文件访问时间


本文整理自网络,侵删。

 
上次访问该文件的时间是什么?
这是如何编写一个函数的示例,该函数将返回文件的上次访问时间(不要与上次修改时间混淆)。

function GetFileLastAccessTime(sFileName: string): TDateTime;
var
  ffd : TWin32FindData;
  dft : DWord;
  lft : TFileTime;
  h   : THandle;
begin
  // get file information
  h := Windows.FindFirstFile(PChar(sFileName), ffd);
  if INVALID_HANDLE_VALUE <> h then
  begin
    // we're looking for just one file, so close our "find"
    Windows.FindClose(h);

    // convert the FILETIME to local FILETIME
    FileTimeToLocalFileTime(ffd.ftLastAccessTime, lft);

    // convert FILETIME to DOS time
    FileTimeToDosDateTime(lft, LongRec(dft).Hi, LongRec(dft).Lo);

    // finally, convert DOS time to TDateTime for use in Delphi's
    // native date/time functions
    Result := FileDateToDateTime(dft);
  end;
end;

GetFileLastAccessTime()将以Delphi TDateTime类型返回给定文件的上次访问时间,您可以使用DateTimeToStr()函数将其转换为字符串。例如:

MessageDlg(
    'c:\config.sys was last accessed on '
    + DateTimeToStr(GetFileLastAccessTime('c:\config.sys')),
    mtInformation, [mbOk], 0
);

相关阅读 >>

Delphi shellexecute 打开文件夹

Delphi获取控件界面图像“新招”

Delphi paramstr的用法

Delphi datamodule1 fdconnection1数据库连接

Delphi 命令行 打开读写txt文件

关于Delphi xe5 firemonkey 手机屏幕自适应程序问题

Delphi ado 动态建立.mdb数据库,表

Delphi 实现拦截api的钩子(hook)

Delphi idhttp http.get 获取json数据

Delphi 拼接文件路径

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...