- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
delphi 上次访问该文件的时间
function GetFileLastAccessTime(sFileName: string): TDateTime;
var
ffd : TWin32FindData;
dft : DWord;
lft : TFileTime;
h : THandle;
begin
// get file information
h := Winapi.Windows.FindFirstFile(PChar(sFileName), ffd);
if INVALID_HANDLE_VALUE <> h then
begin
Winapi.Windows.FindClose(h);
// convert the FILETIME to local FILETIME
FileTimeToLocalFileTime(ffd.ftLastAccessTime, lft);
FileTimeToDosDateTime(lft, LongRec(dft).Hi, LongRec(dft).Lo);
Result := FileDateToDateTime(dft);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MessageDlg(
'c:\config.sys was last accessed on '
+ DateTimeToStr(GetFileLastAccessTime('c:\vcredist_x86.log')),
mtInformation, [mbOk], 0
);
end;