?
Solved

How to get the date a file was created

Posted on 2001-06-25
5
Medium Priority
?
784 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 100 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

770 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