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
 
Paradox ActiveX
ExcelFile Viewer
Paradox Password Recovery
SMMsg suite
Clarion Viewer
DBLoad
dBase Viewer
ABA Document Convert
Protected Storage Viewer
DBISAM Password Recovery
 
 


Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

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

SMReport Autogenerated