Delphi获取文件创建时间、文件最后修改时间


本文整理自网络,侵删。

 
procedure TForm1.Button1Click(Sender: TObject);//获取文件创建时间
var
  FileName: string;
  ti: Integer;
  dt: TDateTime;
begin
  FileName := 'D:\test\Test.txt';
  ti := FileAge(FileName);
  ShowMessage(IntToStr(ti));  //返回: 1030115371, 需要转换
  dt := FileDateToDateTime(ti);  //转换
  ShowMessage(DateTimeToStr(dt));  //2010-11-6 10:01:22
end;

procedure TForm1.Button2Click(Sender: TObject);//获取文件最后修改时间
  procedure DirectoryDateTimeInfo(const path : string) ;
  var
    sr : TSearchRec;
    modifiedTime : TDateTime; // 修改时间
  begin
    if sysUtils.FindFirst(path, faDirectory, sr) = 0 then
      modifiedTime := FileDateToDateTime(sr.Time) ; // 修改时间
    ShowMessage(Format('Last Modified Time: "%s"', [DateTimeToStr(modifiedTime)])) ;
    FindClose(sr) ;
   end;
begin
  DirectoryDateTimeInfo('D:\test\Test.txt');
end;

相关阅读 >>

Delphi内嵌汇编实现�载任意进程的某个dll

Delphi stringgrid常用属性和常用操作

Delphi汉字的拼音简码

Delphi f1026 file not found: ''quickrpt.dcu''解决方法

Delphi apihook createprocess

Delphi跨平台检测网络连接状态

Delphi中ocx的动态注册方法

Delphi treeview �c 自动给标题上加图片

Delphi tstringlist utf8编码保存并开启bom

Delphi在手机桌面图标上显示数字

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



打赏

取消

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

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

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

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

评论

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