[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 955
  • Last Modified:

file create date

How can I find Create date of a file?

I would like to write a delphi code that will tell me
 
the create and modify date of a particular file

Can anyone help me

Thanks in advance

Pandian
0
Pandian012000
Asked:
Pandian012000
  • 4
  • 2
  • 2
  • +3
1 Solution
 
LischkeCommented:
Use FindFirst with the real file name and check the returned TWin32FindData structure. There is all you need.

Ciao, Mike
0
 
PeterLarsenCommented:
I agree with Mike,
There is a ready-to-use sample in the help file !

/PL
0
 
AttarSoftwareCommented:
Can I agree too? ;O)

Tim.
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
LischkeCommented:
Quite heavy traffic for a 25 points question, isn't it? ;-))

Ciao, Mike
0
 
MadshiCommented:
Really!   :-)   (Ehm, of course I agree, too)

Regards, Madshi.
0
 
PeterLarsenCommented:
Last question of the week - have to make my self visible here every week :-)

Go home - its weekend :)
Peter
0
 
Alisher_NCommented:
looks like everybody just eager to grab new Q and answer it in few seconds...

;-)
0
 
zealsoftCommented:
Assume you store the file name in the szFile.

    hDateFile : HFILE;
    CreationTime, LastAccessTime, LastWriteTime: TFILETIME;
    SystemTime : TSYSTEMTIME;

     hDateFile := CreateFile(szFile, GENERIC_READ, FILE_SHARE_READ,
          Nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
      GetFileTime(hDateFile, @CreationTime, @LastAccessTime,
          @LastWriteTime);

      // Set Created time.
      FileTimeToLocalFileTime(CreationTime, CreationTime);
      FileTimeToSystemTime(CreationTime, SystemTime);
0
 
MadshiCommented:
Mike, how about posting an answer with 2 lines of code?    :-)

Regards, Madshi.
0
 
LischkeCommented:
:-/

procedure TMainForm.Button7Click(Sender: TObject);

var
  SR: TSearchRec;
  FileTime: TFileTime;
  SystemTime: TSystemTime;
  CreationDate: TDateTime;

begin
  if FindFirst('N:\Delphi\TOOLS\tnet32.dof', faAnyFile, SR) = 0 then
  begin
    FileTime := SR.FindData.ftCreationTime;
    FileTimeToSystemTime(FileTime, SystemTime);
    CreationDate := SystemTimeToDateTime(SystemTime);
    ShowMessage(DateTimeToStr(CreationDate));
  end;
end;

Pandian, it is very unpolite to reject an answer without given at least a simple description. Keep in mind: we do help you not vice versa!

Ciao, Mike
0
 
LischkeCommented:
Sorry, forgot the FindClose call right after ShowMessage (but within the begin/end block):

    FindClose(SR);


Ciao, Mike
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now