How to get the last modified date of the file resides in the particular directory

Hi,

I am creating a automation tool that registers the dll in the component services ,for this i need last modified date of all the dll's in a particular folder .

So,that i can take the recent one( Last built one ) and register it in the component services.

Give me a solution through Delphi code ? is there any function or property to get the value of the date modified for a particular file ???

Solution will be much appreciated.
renjitkumarAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mahdi78Commented:
try this

function GetFileModifyDate(FileName: string): TDateTime;
var
  h: THandle;
  Struct: TOFSTRUCT;
  lastwrite: Integer;
  t: TDateTime;
begin
  h := OpenFile(PAnsiChar(FileName), Struct, OF_SHARE_DENY_NONE);
  try
    if h <> HFILE_ERROR then
    begin
      lastwrite := FileGetDate(h);
      Result    := FileDateToDateTime(lastwrite);
    end;
  finally
    CloseHandle(h);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if Opendialog1.Execute then
    label1.Caption := DatetoStr(GetFileModifyDate(Opendialog1.FileName));
end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
szakalitCommented:
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;
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.