Solved

How to get the date a file was created

Posted on 2001-06-25
5
760 Views
Last Modified: 2008-02-01
Hi,

Is there a way to get the Date of an EXE or a DLL file when it was created using Delphi 5?

Say, I have an EXE file named MYEXE.EXE. I want to display using maybe a messagebox on my application the date it was created.

TIA,
jrmn

0
Comment
Question by:jrmn
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

by:inthe
Comment Utility
function GetFileDate(TheFileName: string): string;
var  FHandle: integer;
begin
  FHandle := FileOpen(TheFileName, 0);
  try
    Result := DateTimeToStr(FileDateToDateTime(FileGetDate(FHandle)));  finally
    FileClose(FHandle);
  end;
end;


form create

label1.caption := GetFileDate(application.exename);
0
 
LVL 4

Author Comment

by:jrmn
Comment Utility
Hi inthe,

Thanks for the quick reply.
However, I got an "Invalid argument to date encode" error upon running your function.
It seems there's a problem with is line in your function:

Result := DateTimeToStr(FileDateToDateTime(FileGetDate(FHandle)));  finally

Could you please elaborate further? If you can, please show me a solid example.

Thanks,
j
   
0
 

Accepted Solution

by:
Richard_Yu earned 25 total points
Comment Utility
Maybe use the FileAge function is better.

Function GetFileDate(TheFileName: String): String;
Begin
   If FileExists(TheFileName) Then Begin
      Result := DateTimeToStr(FileDateToDateTime(FileAge(TheFileName)));
   End;
End;

Procedure TForm1.FormCreate(Sender: TObject);
Begin
   Label1.Caption := GetFileDate(Application.ExeName);
End;
0
 
LVL 4

Author Comment

by:jrmn
Comment Utility
Hi Richard_Yu,

Thanks for modifying the code presented by inthe...it works fine this time.

To Inthe : Thanks for comment above :-)

jrmn
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
sorry taht first oine was old example ,
had to go away for day so missed the comments but here is another working example for anyone reading..


function GetFileDate(TheFileName: string): string;
 Var
  FStruct : TOFSTRUCT;
  Han1 : Integer;
begin
  Han1 := OpenFile(PChar(TheFileName), FStruct, OF_SHARE_DENY_NONE);
  result := DateTimeToStr(FileDateToDateTime(FileGetDate(Han1)));
 closehandle(Han1);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(GetFileDate(application.exename));
end;

Regards Barry
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video discusses moving either the default database or any database to a new volume.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now