unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,dateutils, ComCtrls, EnhListView, ExtListView,
ExtCtrls, Mask,JclFileUtils;
type
TForm1 =
class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Label3: TLabel;
Edit3: TEdit;
listview1: TdfsExtListView;
Label2: TLabel;
Label4: TLabel;
Edit2: TEdit;
Label5: TLabel;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Label6: TLabel;
Label7: TLabel;
Bevel1: TBevel;
Bevel2: TBevel;
Button3: TButton;
Bevel3: TBevel;
MaskEdit1: TMaskEdit;
MaskEdit2: TMaskEdit;
Bevel4: TBevel;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
procedure Button2Click(Sender: TObject);
procedure doit(filenamef:
string;dis:TDateTime);
private
function SetFileTimes(FileName:
string;
const Created: TDateTime;
const Modified: TDateTime;
const Accessed: TDateTime): Boolean;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.SetFileTimes(FileName:
string;
const Created: TDateTime;
const Modified: TDateTime;
const Accessed: TDateTime): Boolean;
var
FileHandle: Integer;
FTime, FTimeC, FTimeA, FTimeM: TFileTime;
STime: TSystemTime;
TimeFlag: Integer;
begin
TimeFlag := 0;
Result := False;
ZeroMemory(@FTime, SizeOf(FTime));
ZeroMemory(@FTime, SizeOf(FTimeC));
ZeroMemory(@FTime, SizeOf(FTimeM));
ZeroMemory(@FTime, SizeOf(FTimeA));
// Created
if Created > 0
then
begin
DateTimeToSystemTime(Created, STime);
SystemTimeToFileTime(STime, FTime);
LocalFileTimeToFileTime(FTime, FTimeC);
Inc(TimeFlag, 1);
end;
// Accessed
if Accessed > 0
then
begin
DateTimeToSystemTime(Accessed, STime);
SystemTimeToFileTime(STime, FTime);
LocalFileTimeToFileTime(FTime, FTimeA);
Inc(TimeFlag, 2);
end;
// Modified
if Modified > 0
then
begin
DateTimeToSystemTime(Modified, STime);
SystemTimeToFileTime(STime, FTime);
LocalFileTimeToFileTime(FTime, FTimeM);
Inc(TimeFlag, 4);
end;
if TimeFlag = 0
then
begin
Exit;
// Nothing to do
end;
// Get a File Handle
FileHandle := FileOpen(FileName, fmOpenReadWrite + fmShareExclusive);
if FileHandle < 0
then
begin
Exit;
end;
case TimeFlag
of
1: Result := SetFileTime(FileHandle, @FTimeC,
nil,
nil);
2: Result := SetFileTime(FileHandle,
nil, @FTimeA,
nil);
3: Result := SetFileTime(FileHandle, @FTimeC, @FTimeA,
nil);
4: Result := SetFileTime(FileHandle,
nil,
nil, @FTimeM);
5: Result := SetFileTime(FileHandle, @FTimeC,
nil, @FTimeM);
6: Result := SetFileTime(FileHandle,
nil, @FTimeA, @FTimeM);
7: Result := SetFileTime(FileHandle, @FTimeC, @FTimeA, @FTimeM);
end;
FileClose(FileHandle);
end;
procedure TForm1.Button2Click(Sender: TObject);
var sr:TSearchRec;
dis:integer;
offset,off1,off2:TDateTime;
tl:TListItem;
begin
//Überprüfen
listview1.Items.Clear;
off1 := strtodate(maskedit1.text)+encodetime(strtoint(edit2.text),strtoint(edit5.text),0,0);
off2 := strtodate(maskedit2.text)+encodetime(strtoint(edit4.text),strtoint(edit6.text),0,0);
offset := off2-off1;
if findfirst(edit1.text+edit3.text,0,sr) = 0
then begin;
repeat
dis := datetimetofiledate(filedatetodatetime(sr.Time) + offset);
tl := listview1.Items.Add;
tl.Caption := sr.
Name;
tl.SubItems.Add(datetimetostr(filedatetodatetime(sr.Time)));
tl.SubItems.Add(datetimetostr(filedatetodatetime(dis)));
// if sender=button2 then begin;
doit(edit1.Text+sr.
Name,dis);
// end;
UNTIL FindNext(sr) <> 0;
findclose(sr);
end;
end;
procedure TForm1.doit(filenamef:
string;dis:TDateTime);
begin;
SetFileTimes(filenamef,dis,dis,dis);
if (getlasterror>0)
then showmessage(inttostr(getlasterror));
end;
end.