Source
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
DateTimePicker1: TDateTimePicker;
DateTimePicker2: TDateTimePicker;
Button2: TButton;
Label1: TLabel;
OpenDialog1: TOpenDialog;
Edit1: TEdit;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses DateUtils;
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
var
newDateTime: TDateTime;
y,m,d,HH,MM,SS,MS: word;
fileName: String;
fileDate: Integer;
begin
fileName:= Edit1.text;
if FileExists(fileName) then begin
DecodeDate(DateTimePicker1.Date, y,m,d);
DecodeTime(DateTimePicker2.Time, HH,MM,SS,MS);
MS := 999;
newDateTime := EncodeDateTime(y,m,d,HH,MM,SS, MS);
FileSetDate(fileName, DateTimeToFileDate(newDateTime));
fileDate := FileAge(fileName);
if fileDate > -1 then
showmessage(fileName + ' last modified date = '+DateTimeToStr(FileDateToDateTime(fileDate)));
end
else Showmessage ('Find not found !');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then begin
Edit1.Text := OpenDialog1.FileName;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DateTimePicker1.Date := Date;
DateTimePicker2.Time:= Time;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
DateTimePicker1: TDateTimePicker;
DateTimePicker2: TDateTimePicker;
Button2: TButton;
Label1: TLabel;
OpenDialog1: TOpenDialog;
Edit1: TEdit;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses DateUtils;
{$R *.dfm}
procedure TForm1.Button2Click(Sender: TObject);
var
newDateTime: TDateTime;
y,m,d,HH,MM,SS,MS: word;
fileName: String;
fileDate: Integer;
begin
fileName:= Edit1.text;
if FileExists(fileName) then begin
DecodeDate(DateTimePicker1.Date, y,m,d);
DecodeTime(DateTimePicker2.Time, HH,MM,SS,MS);
MS := 999;
newDateTime := EncodeDateTime(y,m,d,HH,MM,SS, MS);
FileSetDate(fileName, DateTimeToFileDate(newDateTime));
fileDate := FileAge(fileName);
if fileDate > -1 then
showmessage(fileName + ' last modified date = '+DateTimeToStr(FileDateToDateTime(fileDate)));
end
else Showmessage ('Find not found !');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then begin
Edit1.Text := OpenDialog1.FileName;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DateTimePicker1.Date := Date;
DateTimePicker2.Time:= Time;
end;
end.
------------
object Form1: TForm1
Left = 256
Top = 205
Width = 1305
Height = 675
Caption = 'How to Change the Last Modified Date with Delphi.'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 344
Top = 112
Width = 43
Height = 13
Caption = 'File path:'
end
object Button1: TButton
Left = 664
Top = 160
Width = 75
Height = 25
Caption = '...'
TabOrder = 0
OnClick = Button1Click
end
object Edit1: TEdit
Left = 344
Top = 128
Width = 401
Height = 21
TabOrder = 1
end
object DateTimePicker1: TDateTimePicker
Left = 344
Top = 208
Width = 186
Height = 21
Date = 43796.000000000000000000
Time = 43796.000000000000000000
TabOrder = 2
end
object DateTimePicker2: TDateTimePicker
Left = 544
Top = 208
Width = 186
Height = 21
Date = 43796.000000000000000000
Time = 43796.000000000000000000
Kind = dtkTime
TabOrder = 3
end
object Button2: TButton
Left = 664
Top = 240
Width = 75
Height = 25
Caption = 'Set'
TabOrder = 4
OnClick = Button2Click
end
object OpenDialog1: TOpenDialog
DefaultExt = 'pas'
Filter = 'Object/Pascal (*.pas)|*.pas|Delphi Form (*.dfm)|*.dfm'
Left = 440
Top = 32
end
end
Comments
Post a Comment