这个就可以。
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: do
uble;
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;