欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

Delphi中取得和设置硬盘上文件的创建日期、修改日期、访问日期、文件属性

发布时间:2025/5/22 编程问答 37 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Delphi中取得和设置硬盘上文件的创建日期、修改日期、访问日期、文件属性 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

 

Delphi中取得和设置硬盘上文件的创建日期、修改日期、访问日期、文件属性

function FileAge(const FileName: string): Integer; $[SysUtils.pas
功能 返回文件创建的时间
说明 文件不存在则返回-1
参考 function Windows.FindFirstFile
例子
///Begin FileAge,DateTimeToStr,FileDateToDateTime
procedure TForm1.Button1Click(Sender: TObject);
begin
SpinEdit1.Value := FileAge(Edit1.Text);
if SpinEdit1.Value > 0 then
Edit2.Text := DateTimeToStr(FileDateToDateTime(SpinEdit1.Value));
end;
///End FileAge,DateTimeToStr,FileDateToDateTime
首部 function FileGetDate(Handle: Integer): Integer; $[SysUtils.pas
功能 返回文件的修改时间
说明 读取失败则返回-1
参考 function Windows.GetFileTime
例子
///Begin FileGetDate
procedure TForm1.Button1Click(Sender: TObject);
var
I: Integer;
begin
I := FileOpen(Edit1.Text, fmOpenRead);
if I < 0 then Exit;
SpinEdit1.Value := FileGetDate(I);
Edit2.Text := DateTimeToStr(FileDateToDateTime(SpinEdit1.Value));
FileClose(I);
end;
///End FileGetDate
────────────────────────
首部 function FileSetDate(const FileName: string; Age: Integer): Integer; overload; $[SysUtils.pas
首部 function FileSetDate(Handle: Integer; Age: Integer): Integer; overload; platform; $[SysUtils.pas
功能 返回设置文件的修改时间
说明 修改成功则返回0
参考 function Windows.SetFileTime
例子 SpinEdit1.Value := FileSetDate(Edit1.Text, DateTimeToFileDate(StrToDateTime(Edit2.Text)));
────────────────────────
首部 function FileGetAttr(const FileName: string): Integer; platform; $[SysUtils.pas
功能 返回文件的属性
说明 读取失败则返回$FFFFFFFF
参考 function Windows.GetFileAttributes
例子 SpinEdit1.Value := FileGetAttr(Edit1.Text);
────────────────────────
首部 function FileSetAttr(const FileName: string; Attr: Integer): Integer; platform; $[SysUtils.pas
功能 返回设置文件的属性
说明 设置成功则返回0
参考 function Windows.SetFileAttributes
例子 SpinEdit1.Value := FileSetAttr(Edit1.Text, SpinEdit2.Value);


──────────────────────── ---------------------------转载于百度某某大侠的博客!-------------------------------------------------------

 

转载于:https://www.cnblogs.com/doutian/archive/2012/10/29/2745406.html

总结

以上是生活随笔为你收集整理的Delphi中取得和设置硬盘上文件的创建日期、修改日期、访问日期、文件属性的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。