1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| function GetFileTimes(const FileName: string; var Created: TDateTime;
var Accessed: TDateTime; var Modified: TDateTime): Boolean;
var
h: THandle;
Info1, Info2, Info3: TFileTime;
SysTimeStruct: SYSTEMTIME;
TimeZoneInfo: TTimeZoneInformation;
Bias: Double;
begin
Result := False;
Bias := 0;
h := FileOpen(FileName, fmOpenRead or fmShareDenyNone);
if h > 0 then
begin
try
if GetTimeZoneInformation(TimeZoneInfo) <> $FFFFFFFF then
Bias := TimeZoneInfo.Bias / 1440; // 60x24
GetFileTime(h, @Info1, @Info2, @Info3);
if FileTimeToSystemTime(Info1, SysTimeStruct) then
Created := SystemTimeToDateTime(SysTimeStruct) - Bias;
if FileTimeToSystemTime(Info2, SysTimeStruct) then
Accessed := SystemTimeToDateTime(SysTimeStruct) - Bias;
if FileTimeToSystemTime(Info3, SysTimeStruct) then
Modified := SystemTimeToDateTime(SysTimeStruct) - Bias;
Result := True;
finally
FileClose(h);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Date1, Date2, Date3: TDateTime;
begin
if GetFileTimes(Edit1.Text, Date1, Date2, Date3) then
begin
ShowMessage('Created: ' + DateTimeToStr(Date1));
ShowMessage('Last Accessed: ' + DateTimeToStr(Date2));
ShowMessage('Last Modified: ' + DateTimeToStr(Date3));
end;
end; |
Partager