Solved

How to get the date a file was created

Posted on 2001-06-25
5
779 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

728 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