Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reset the File Creation datetime

Status
Not open for further replies.

LucieLastic

Programmer
May 9, 2001
1,694
GB
hi All

We've copied over a load of files but lost the creation datetimes on them. I need to set the actual Creation datatime of the newly copied files to their original datetimes. I've looked at FileAge but this gives me the LastModified datetime and I don't want that.

I'm having trouble getting something working, so if anyone can help with some sample code, as struggling a bit at the mo, I'd be extremely grateful.

Many thanks in advance
lou

www.radbmx.co.uk
 
Hi Lucie

Have you looked at the WIN32_FILE_ATTRIBUTE_DATA structure I think you can acess it with the getfielattributes API call.

Code:
typedef struct _WIN32_FILE_ATTRIBUTE_DATA{  
    DWORD      dwFileAttributes; 
    FILETIME   ftCreationTime; 
    FILETIME   ftLastAccessTime; 
    FILETIME   ftLastWriteTime; 
    DWORD      nFileSizeHigh; 
    DWORD      nFileSizeLow; 
} WIN32_FILE_ATTRIBUTE_DATA, *LPWIN32_FILE_ATTRIBUTE_DATA;


Steve [The sane]: Delphi a feersum engin indeed.
 
Thanks Steve.

I've got it working like this:

Code:
procedure TForm1.Button1Click(Sender: TObject);
  var OK         : boolean;
      hOld, hNew : THandle;
      CreationDT : TFileTime;
begin
  TRY
    hOld := fileopen(edSourceFile.text, fmOpenRead or fmShareDenyNone);
    hNew := fileopen(edDestFile.text,   fmOpenReadWrite or fmShareDenyNone);
    TRY
      OK := GetFileTime(hOld, @CreationDT, nil, nil);
      if OK then
      begin
        OK := SetFileTime(hNew, @CreationDT, nil, nil);
        if not OK then showmessage('FAILED');
      end
      else showmessage('Failed');
    FINALLY
      Fileclose(hOld);
      Fileclose(hNew);
    END;
  EXCEPT
    on e:exception do
      Showmessage('Failed - '+e.message);
  END;
end;

www.radbmx.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top