Registriert seit: 31. Okt 2003
1.120 Beiträge
Delphi 7 Personal
|
Re: Dateieigenschaften ändern
8. Jan 2004, 12:27
Delphi-Quellcode:
function FileTimeToDateTime(ft : FILETIME) : TDateTime;
var
st : SYSTEMTIME;
lt : FILETIME;
begin
FillChar(st, SizeOf(st), 0);
FillChar(lt, SizeOf(lt), 0);
FileTimeToLocalFileTime(ft, lt);
FileTimeToSystemTime(lt, st);
result := SystemTimeToDateTime(st);
end;
function DateTimeToFileTime(dt : TDateTime) : FILETIME;
var
st : SYSTEMTIME;
lt : FILETIME;
begin
FillChar(st, SizeOf(st), 0);
FillChar(lt, SizeOf(lt), 0);
FillChar(result, SizeOf(result), 0);
DateTimeToSystemTime(dt, st);
SystemTimeToFileTime(st, lt);
LocalFileTimeToFileTime(lt, result);
end;
//...
var
fh : THandle;
fn : string;
fCreationTime : FileTime;
fLastAccessTime : FileTime;
fLastWriteTime : FileTime;
TempDateTime : TDateTime;
begin
fn := 'C:\test.txt';
fh := FileOpen(fn, fmOpenRead);
GetFileTime(fh, @fCreationTime, @fLastAccessTime, @fLastWriteTime);
TempDateTime := FileTimeToDateTime(fCreationTime);
// Hier manipulieren
fCreationTime := DateTimeToFileTime(TempDateTime);
SetFileTime(fh, @fCreationTime, @fLastAccessTime, @fLastWriteTime);
CloseHandle(fh);
end;
|
|
Zitat
|