1. Home
  2. Computing & Technology
  3. Delphi Programming

Set File Date (created)

By , About.com Guide

Here's a procedure to change the created date "attribute" for a given file:

~~~~~~~~~~~~~~~~~~~~~~~~~
function SetFileDate(
   Const FileName : String;
   Const FileDate : TDateTime): Boolean;
var
  FileHandle : THandle;
  FileSetDateResult : Integer;
begin
  try
   try
    FileHandle := FileOpen
       (FileName,
        fmOpenWrite OR fmShareDenyNone) ;
    if FileHandle > 0 Then begin
     FileSetDateResult :=
       FileSetDate(
         FileHandle,
         DateTimeToFileDate(FileDate)) ;
       result := (FileSetDateResult = 0) ;
     end;
   except
    Result := False;
   end;
  finally
   FileClose (FileHandle) ;
  end;
end;

{Usage:}
SetFileDate('c:\mydir\myfile.ext', Now)

~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Get EXE Version Information
« TButton with multiline Caption

Explore Delphi Programming
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2001 Delphi Tips
  7. Set File Date (created)

©2010 About.com, a part of The New York Times Company.

All rights reserved.