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中关闭“返回值…可能未定义”的警告

Delphi过滤字符串头部和尾部得到中间部分

Delphi获取默认浏览器

Delphi 10 seattle的android应用程序中使用参数启动服务

Delphi setpriorityclass 设置当前程序的优先级

Delphi 制作一个内网传播的程序

Delphi中比较两个字符串相似性的百分比算法

Delphi webbrowser 加载html成web

Delphi编程实现图像的淡入浅出

Delphi 操作“任务栏”

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



打赏

取消

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

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

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

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

评论

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