使用函数:
System.IOUtils.TDirectory.GetCreationTime
System.IOUtils.TDirectory.GetLastAccessTime
System.IOUtils.TDirectory.GetLastWriteTime
System.IOUtils.TDirectory.SetCreationTime
System.IOUtils.TDirectory.SetLastAccessTime
System.IOUtils.TDirectory.SetLastWriteTime
代码:
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.FileCtrl, System.IOUtils; type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Label3: TLabel; Edit_CreateTime: TEdit; Edit_AccessTime: TEdit; Edit_WriteTime: TEdit; Button1: TButton; Button_GetTime: TButton; Button_SetTime: TButton; procedure Button1Click(Sender: TObject); procedure Button_GetTimeClick(Sender: TObject); procedure Button_SetTimeClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} var sDir: string; procedure TForm1.Button1Click(Sender: TObject); begin if not SelectDirectory('', 'H:\tmp', sDir)then Exit; Text := sDir; end; procedure TForm1.Button_GetTimeClick(Sender: TObject); //GetTime begin try Edit_CreateTime.Text := DateTimeToStr(TDirectory.GetCreationTime(sDir)); Edit_AccessTime.Text := DateTimeToStr(TDirectory.GetLastAccessTime(sDir)); Edit_WriteTime.Text := DateTimeToStr(TDirectory.GetLastWriteTime(sDir)); except on e: Exception do begin MessageDlg(e.ClassName + ' : ' + e.Message, mtError, [mbok], 0); Exit; end; end; end; procedure TForm1.Button_SetTimeClick(Sender: TObject); //SetTime begin try TDirectory.SetCreationTime(sDir, StrToDateTime(Edit_CreateTime.Text)); TDirectory.SetLastAccessTime(sDir, StrToDateTime(Edit_AccessTime.Text)); TDirectory.SetLastWriteTime(sDir, StrToDateTime(Edit_WriteTime.Text)); ShowMessage('设置完成!'); except on e: Exception do begin MessageDlg(e.ClassName + ' : ' + e.Message, mtError, [mbok], 0); Exit; end; end; end; end.