作者在 2010-01-25 17:12:59 发布以下内容
unit MainUnit;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TMainForm = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Label2: TLabel;
Edit2: TEdit;
Button2: TButton;
Label3: TLabel;
Edit3: TEdit;
Label4: TLabel;
Edit4: TEdit;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation
{$R *.DFM}
function GetFilesTime(sFilename: String; Timetype: Integer): TDateTime;
var
ffd: TWin32FindData;
dft: DWord;
lft, Time: TFileTime;
sHandle: THandle;
begin
sHandle:= Windows.FindFirstFile(PChar(sFileName), ffd);
if (sHandle <>INVALID_HANDLE_VALUE) then
begin
case Timetype of
0: Time:= ffd.ftCreationTime;
1: Time:= ffd.ftLastWriteTime;
2: Time:= ffd.ftLastAccessTime;
end;
Windows.FindClose(sHandle);
FileTimeToLocalFileTime(Time, lft);
FileTimeToDosDateTime(lft, LongRec(dft).HI, LongRec(dft).Lo);
Result:= FileDateToDateTime(dft);
end else Result:= 0;
end;
procedure TMainForm.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then
Edit1.Text:= OpenDialog1.FileName;
end;
procedure TMainForm.Button2Click(Sender: TObject);
begin
if Edit1.Text<> '' then
begin
Edit2.Text:= DateToStr(GetFilesTime(Edit1.Text, 0));
Edit3.Text:= DateToStr(GetFilesTime(Edit1.Text, 1));
Edit4.Text:= DateToStr(GetFilesTime(Edit1.Text, 2));
end
else ShowMessage('请指定文件!');
end;
end.