Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2006 Oct : Set File Creation Time

www.cryer.info
Managed Newsgroup Archive

Set File Creation Time

Subject:Set File Creation Time
Posted by:"DeeDub" (davetwel..@yahoo.com)
Date:2 Oct 2006 11:48:30

I have a function that successfully sets the creation date of
a file equal to the creation date of another file.  Here is an
example, although this isn't exactly what I am doing:

procedure mySetFileTime(FromFile, ToFile: string);
var
  NewFileTime : TFileTime;
  TmpFileTime : TFiletime;
  SystemTime  : TSystemtime;
  fStream     : TFileStream;
begin
  fStream := TFileStream.Create(ToFile, fmOpenWrite);
  try
    DateTimeToSystemTime(FileDateToDateTime(FileAge(FromFile)), SystemTime);
    SystemTimeToFileTime(SystemTime, TmpFileTime);
    LocalFileTimeToFiletime(TmpFileTime, NewFileTime);
    SetFileTime(fStream.Handle, @NewFileTime, nil, nil);
  finally
     fStream.Free;
  end;
end;

When I was trying to get this to behave the way I wanted it to,
something peculiar was happening.  Initially, I had another
variable to which I assigned the FileDateToDateTime function.
Exactly the same code as above, except:

procedure mySetFileTime(FromFile, ToFile: string);
var
  NewFileTime : TFileTime;
  TmpFileTime : TFiletime;
  TmpDateTime : TDateTime; // new
  SystemTime  : TSystemtime;
  fStream     : TFileStream;
begin
  fStream := TFileStream.Create(ToFile, fmOpenWrite);
  try
    TmpDateTime := FileDateToDateTime(FileAge(FromFile)); // new
    DateTimeToSystemTime(TmpDateTime, SystemTime);
    SystemTimeToFileTime(SystemTime, TmpFileTime);
    LocalFileTimeToFiletime(TmpFileTime, NewFileTime);
    SetFileTime(fStream.Handle, @NewFileTime, nil, nil);
  finally
     fStream.Free;
  end;
end;

This function, however, did not work.  Can anyone explain why
this would be the case?

Thanks in advance
D

Replies:

www.cryer.info
Managed Newsgroup Archive