Scalabium Software

SMReport Autogenerated

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;
var
  hFile: THandle;
begin
  Result := False;
  try
    {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)
  finally
    {close an opened file handle}
    FileClose(hFile);
  end;
end;

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
 
Metafile Convert
dBase Viewer
ABA Document Convert
DBISAM Viewer
Word Web-stream
ABA Spreadsheet Convert
Paradox Password Recovery
Excel Reader (dll)
Clarion Viewer
Viewer for MS Outlook Messages
 
 
Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2014, Scalabium Software. All rights reserved.
webmaster@scalabium.com

SMExport advertising