function 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;
/////////////////////////////
/// Aufruf
////////////////////////
procedure TForm1.Button3Click(Sender: TObject);
var wfn:
string;
d: Tsearchrec;
FT: TFiletime;
ST: TSYSTEMTIME;
DT: TDateTime;
I, H: Integer;
begin
if Edit1.Text = '
'
then Exit:
// kein Pfad angegeben
DT := Now;
// 35065 = 1.1.1996 0 Uhr;
DecodeTime(DT, ST.wHour, ST.wMinute, ST.wSecond, St.wMilliseconds);
DecodeDate(DT, ST.wYear, ST.wMonth, ST.wDay);
SystemTimeToFileTime(ST, ft);
h := FileOpen(Edit1.Text, fmopenwrite);
SetFileTime(h, @ft, @ft, @ft);
FileClose(h);
end;