Recent

Author Topic: GetFTime. What is correct way get file modification time?  (Read 704 times)

mika

  • Full Member
  • ***
  • Posts: 111
GetFTime. What is correct way get file modification time?
« on: December 11, 2023, 11:23:34 am »
Is there some simple, consistent, platform independent way to get file modification time?

Unit "dos" is declared as "compatibility unit" for TP. If i use dos.GetFTime under linux it gives 1 hour off for summer time.

In linux i can use BaseUnix.FpStat and then unixutil.EpochToLocal convert st_mtime to human readable format. Then it is not my local time, but global. Even in documetatin is stated that EpochToLocal use correction for time zone.

I'm targeting dos (in dosbox) and linux and want to get matching results.

jamie

  • Hero Member
  • *****
  • Posts: 6735
The only true wisdom is knowing you know nothing

Hartmut

  • Hero Member
  • *****
  • Posts: 853
Re: GetFTime. What is correct way get file modification time?
« Reply #2 on: December 11, 2023, 07:17:52 pm »
Did you try sysutils.FileGetDate() = https://www.freepascal.org/docs-html/current/rtl/sysutils/filegetdate.html or sysutils.FileAge() = https://www.freepascal.org/docs-html/current/rtl/sysutils/fileage.html ?

The 1st needs a handle. If you need help to provide this, let me know.

jcmontherock

  • Sr. Member
  • ****
  • Posts: 272
Re: GetFTime. What is correct way get file modification time?
« Reply #3 on: December 11, 2023, 09:47:45 pm »
It's that I am using:

Code: Pascal  [Select][+][-]
  1. function TForm1.FileTime2DateTime(fFileTime: FILETIME{; bWithTime: Boolean = True}): TDateTime;
  2. Var
  3.   LocalFileTime:  FILETIME;
  4.   SystemFileTime: SYSTEMTIME;
  5. begin
  6.   {$HINTS OFF}
  7.   FileTimeToLocalFileTime(fFileTime, LocalFileTime);
  8.         FileTimeToSystemTime(LocalFileTime, SystemFileTime);
  9.   Result := SystemTimeToDateTime(SystemFileTime);
  10.   {$HINTS ON}
  11.   //if bWithTime = True then Result := SystemTimeToDateTime(SystemFileTime)           // With Time
  12.   //else                     Result := Trunc(SystemTimeToDateTime(SystemFileTime));   // Without time
  13. end;
  14.  
Windows 11 UTF8-64 - Lazarus 4RC1-64 - FPC 3.2.2

 

TinyPortal © 2005-2018