Solved

How to get the date a file was created

Posted on 2001-06-25
5
770 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 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