//-----------------------------------------------------------------------//
//#######################################################################//
//## Function SetFileTimes: ##//
//#######################################################################//
//## Datum: Änderung: ##//
//## ====== ========= ##//
//## 30.12.2000 Initial Release ##//
//#######################################################################//
function SetFileTimes(FileName:
string;
const Created: TDateTime;
const Modified: TDateTime;
const Accessed: TDateTime): Boolean;
overload;
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;