Scalabium Software

SMExport/SMImport suites
Knowledge for your independence'.
Home Delphi and C++Builder tips

#122: How can I change a creation date/time for some file on disk?

Today I want to show how you can change a datetime of file creation from own application:

function SetDateToFile(const FileName: string; Value: TDateTime): Boolean;
  hFile: THandle;
  Result := False;
    {open a file handle}
    hFile := FileOpen(FileName, fmOpenWrite or fmShareDenyNone);

    {if opened succesfully}
    if (hFile > 0) then
      {convert a datetime into DOS format and set a date}
      Result := (FileSetDate(hFile, DateTimeToFileDate(Value)) = 0)
    {close an opened file handle}

To use:
SetDateToFile('C:\My Documents\application.cfg', Now());

This code can be useful in case of application protection - you can store in creation date of some your file a same important value. For example, version of application or date of first start for your trial.

Published: August 13, 2001

See also
ABA Document Convert
Database Information Manager
Paradox ActiveX
Word Web-stream
SMMsg suite
Metafile Convert
Paradox to MS Access converter
Paradox to Text converter
Viewer for TNEF-files (winmail.dat)

Contact to webmaster


Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2024, Scalabium Software. All rights reserved.

SMExport/SMImport suites