Solved

How to get the date a file was created

Posted on 2001-06-25
5
765 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
ID: 6226344
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
ID: 6226454
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
ID: 6226514
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
ID: 6226747
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
ID: 6228646
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 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

18 Experts available now in Live!

Get 1:1 Help Now