Recent

Author Topic: Getting the Directory'Folder date?  (Read 278 times)

QEnnay

  • Full Member
  • ***
  • Posts: 110
Getting the Directory'Folder date?
« on: September 14, 2022, 05:41:58 pm »
Linux Mine+Mate, Laz-2.0.12

My backup modifies the base-folder-path date on the target drive to the current date using

Code: Pascal  [Select][+][-]
  1.   strFpSystem:='touch ' ...
  2.   fpSystem(strFpSystem);
  3.  

I would like to read that same folder Date in an AfterScroll function for a database.

I have searched and found, **DirectoryAge()** here, but the compiler spits it out.

How can I get that Directory/Folder age to display in a Label.Caption by any Lazarus/FPC/Linux method?

The FPC Wiki on **fpSystem** is way too cryptic for my old brain. :)


Linux-Mint 20.1 x64 + Cinnamon; Lenovo Flex 5 Ryzen 5 4500, 16GB memory
FPC: 3.2.0-1, Lazarus 2.0.12-0, all 64bit

KodeZwerg

  • Hero Member
  • *****
  • Posts: 568
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Getting the Directory'Folder date?
« Reply #1 on: September 14, 2022, 06:01:14 pm »
FileAge() should deliver what you want, maybe needs to be converted with FileDateToDateTime() afterwards but i am extreme unskilled with non-windows OS.
« Last Edit: Tomorrow at 31:76:97 by KodeZwerg »

MarkMLl

  • Hero Member
  • *****
  • Posts: 5595
Re: Getting the Directory'Folder date?
« Reply #2 on: September 14, 2022, 06:07:00 pm »
Since you're already using fpSystem() one the obvious way would be to use something like

Code: Text  [Select][+][-]
  1. ~$ ls -ld Downloads
  2.  
  3. # or alternatively
  4.  
  5. ~$ ls -d --full-time Downloads
  6.  

and parse the output. However I think that you might find fpStat() a bit more immediately useful since the dates will be in machine format.

I don't know whether you can streamline that touch by using something like FileSetDate(). In any event, I suggest that you could usefully familiarise yourself with the documentation at https://www.freepascal.org/docs.html , noting that this is /documentation/ rather than just "a wiki" or some random website (I'd like to think that I'm stating the obvious, but you'd be surprised how many people have at best a dim appreciation of the distinction :-)

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Fred vS

  • Hero Member
  • *****
  • Posts: 2836
    • StrumPract is the musicians best friend
Re: Getting the Directory'Folder date?
« Reply #3 on: September 14, 2022, 07:02:54 pm »
Hello.

You may use FpStat from baseunix unit:
https://www.freepascal.org/docs-html/rtl/baseunix/fpstat.html

Code: Pascal  [Select][+][-]
  1. program fstat_date;
  2.  
  3. uses BaseUnix;
  4.  
  5. var
  6.     info : stat;
  7.  
  8. begin
  9.    if fpstat ('/home/you/',info)<>0 then  // in Unix a directory is a file
  10.      begin
  11.        writeln('Fstat failed. Errno : ',fpgeterrno);
  12.        halt (1);
  13.      end;
  14.    writeln ('ctime   : ',info.st_ctime); //  File creation time
  15.    writeln ('ctime_nsec   : ',info.st_ctime_nsec); // File creation time with nanosecond precision
  16.  
  17.    writeln ('atime   : ',info.st_atime); //  Last file access time
  18.    writeln ('atime_nsec   : ',info.st_atime_nsec); // Access time with nanosecond precision
  19.  
  20.    writeln ('mtime   : ',info.st_mtime); //  Last file modification time
  21.    writeln ('mtime_nsec   : ',info.st_mtime_nsec); // Last file modification time e with nanosecond precision
  22.  end.
« Last Edit: September 14, 2022, 07:57:50 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

QEnnay

  • Full Member
  • ***
  • Posts: 110
Re: Getting the Directory'Folder date?
« Reply #4 on: September 14, 2022, 08:00:36 pm »
FileAge()

Thanks, I had tried that but it returns -1. Also I read where the wiki stated it would not work on Directories, but I had already tried that anyway.
Linux-Mint 20.1 x64 + Cinnamon; Lenovo Flex 5 Ryzen 5 4500, 16GB memory
FPC: 3.2.0-1, Lazarus 2.0.12-0, all 64bit

QEnnay

  • Full Member
  • ***
  • Posts: 110
Re: Getting the Directory'Folder date?
« Reply #5 on: September 14, 2022, 08:02:55 pm »
You may use FpStat from baseunix unit:
https://www.freepascal.org/docs-html/rtl/baseunix/fpstat.html

Thanks for the details, I will try that, very much appreciated.
Linux-Mint 20.1 x64 + Cinnamon; Lenovo Flex 5 Ryzen 5 4500, 16GB memory
FPC: 3.2.0-1, Lazarus 2.0.12-0, all 64bit

 

TinyPortal © 2005-2018