【文件属性】:
文件名称:Delphi 获取文件访问时间.rar
文件大小:7KB
文件格式:RAR
更新时间:2022-07-30 11:48:23
Delphi源码-文件操作
Delphi 获取文件访问时间,也主是最后一次打开文件 的时间,基于Delphi7实现。相关代码如下:
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
Edit1.Text := OpenDialog1.FileName;
Edit2.Text := '';
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if Edit1.Text<>'' then
Edit2.Text := GetDateTime(Pchar(OpenDialog1.FileName));
end;
function TForm1.GetDateTime(const FileName: Pchar): string;
var
hFile : THandle;
Sy : TSecurityAttributes;
WTime, LTime : TFILETIME;
STime : TSystemTime;
begin
Sy.nLength := SizeOf(TSecurityAttributes);
//必需参数
Sy.lpSecurityDescriptor := nil;
Sy.bInheritHandle:=False;
hFile := CreateFile(PChar(FileName),GENERIC_READ , 1 ,@Sy,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 1);
if hFile=INVALID_HANDLE_VALUE then
Result:=''
else
begin
GetFileTime(hFile, nil, @WTime, nil);
FileTimeToLocalFileTime(WTime, LTime);
FileTimeToSystemTime(LTime, STime);
Result:=Format('%d年%d月%d日 %2.2d:%2.2d:%2.2d',[STime.wYear,STime.wMonth,STime.wDay,STime.wHour,STime.wMinute,STime.wSecond]);
end;
end;
【文件预览】:
srcfans.com
----获取文件访问时间()
--------Project1.res(876B)
--------Unit1.dfm(1KB)
--------Unit1.ddp(51B)
--------Project1.cfg(461B)
--------Unit1.pas(2KB)
--------Project1.dpr(188B)
--------Project1.dof(2KB)
--------Unit1.dcu(5KB)