DelphiBasics
FileAge
Function
Get the last modified date/time of a file without opening it SysUtils unit
 function FileAge ( const FileName : string ) : Integer;
Description
The FileAge function returns the last modified date and time of a file FileName.
 
There is no need to open or close the file - this function handles these operations silently for you.
 
The returned value is in a 32 bit partitioned format. Use the FiledateToDateTime function to convert into a manageable TDateTime value.
 
If the file date could not be found (for example, the FileName was invalid), then -1 is returned.
Related commands
DateTimeToFileDate Convert a TDateTime value to a File date/time format
FileDateToDateTime Converts a file date/time format to a TDateTime value
FileSetDate Set the last modified date and time of a file
FileGetAttr Gets the attributes of a file
FileSetAttr Sets the attributes of a file
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 Download this web site as a Windows program.




 
Example code : Get the last modified date of the current Unit form file
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
 
unit Unit1;
 
interface
 
uses
  SysUtils,   // Unit containing the FileAge command
  Forms, Dialogs;
 
type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  end;
 
var
  
Form1: TForm1;
 
implementation
{$R *.dfm} // Include form definitions
 
procedure TForm1.FormCreate(Sender: TObject);

var
  fileName   : string;
  fileDate   : Integer;

begin
  // Try to open the Unit1.DCU file for the current project
  fileName := 'Unit1.DCU';
  fileDate := FileAge(fileName);

  // Did we get the file age OK?
  if fileDate > -1 then
    ShowMessage(fileName+' last modified date = '+
                DateToStr(FileDateToDateTime(fileDate)));
end;
 
end.
Hide full unit code
   Unit1.DCU last modified date = 10/11/2002
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page