Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2014-10

Getting the last modified date of a directory

12 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jürgen Hestermann
to Richard Mace
Richard Mace wrote
Hi All, I can see that we have a "FileAge" function and also a "FileGetDate" however, I was wondering what the best way of getting the last modified date of a folder? Effectively, the last time that a file was created/changed within a folder?

I think that "FileAge" should work for directory names too. Have not tested though.

The question is: What does a directory date tell you? -------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141026/3c6e0802/attachment.html>

Reply by email

Richard Mace
to Jürgen Hestermann: I think that "FileAge" should work for directory names too. Have not tested though. The…

I want to know the last time any file was created or modified within a given folder which I believe is represented in windows via the last modified date next to the folder?

Richard

"J?rgen Hestermann" wrote 21 lines
Am 2014-10-25 um 19:19 schrieb Richard Mace: Hi All, I can see that we have a "FileAge" function and also a "FileGetDate" however, I was wondering what the best way of getting the last modified date of a folder? Effectively, the last time that a file was created/changed within a folder? I think that "FileAge" should work for directory names too. Have not tested though. The question is: What does a directory date tell you? -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141026/6a6f86db/attachment.html>

Reply by email

Jürgen Hestermann
to Reinier Olislagers: Why do you think that? The docs say it doesn't:…
Reinier Olislagers wrote 6 lines
On 26/10/2014 10:09, J?rgen Hestermann wrote: > I think that "FileAge" should work for directory names too. Why do you think that? The docs say it doesn't: http://www.freepascal.org/docs-html/rtl/sysutils/fileage.html

At least on Windows there is no difference
to retrieve the date of a file or a directory:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms724320%28v=vs.85%29.aspx says:
"Retrieves the date and time that a file *or directory* was created, last accessed, and last modified." Nevertheless, I don't know whether this is true for other OS's too.

Reply by email

Jürgen Hestermann
to Richard Mace: I want to know the last time any file was created or modified within a given folder which…
Richard Mace wrote
I want to know the last time any file was created or modified within a given folder which I believe is represented in windows via the last modified date next to the folder?

I am not sure when exactly directory dates are changed and whether this behaviour is identical for all OS's (supported by Free Pascal). When metadata of a directory is modified it can also change the "last modified" date. This may not always be as expected.

Reply by email

Reinier Olislagers
to Jürgen Hestermann: At least on Windows there is no difference to retrieve the date of a file or a directory:…
J?rgen Hestermann wrote 10 lines
Am 2014-10-26 um 10:29 schrieb Reinier Olislagers: > On 26/10/2014 10:09, J?rgen Hestermann wrote: >> I think that "FileAge" should work for directory names too. > Why do you think that? > The docs say it doesn't: > http://www.freepascal.org/docs-html/rtl/sysutils/fileage.html > At least on Windows there is no difference to retrieve the date of a file or a directory:

Why are you quoting MSDN WinAPI help instead of FreePascal keyword help?

The FPC docs clearly state the return value is -1 in case of
directories. Have you tested it?

Reply by email

Jürgen Hestermann
to Reinier Olislagers
Reinier Olislagers wrote 10 lines
On 26/10/2014 11:45, J?rgen Hestermann wrote: > Am 2014-10-26 um 10:29 schrieb Reinier Olislagers: >> On 26/10/2014 10:09, J?rgen Hestermann wrote: >>> I think that "FileAge" should work for directory names too. >> Why do you think that? >> The docs say it doesn't: >> http://www.freepascal.org/docs-html/rtl/sysutils/fileage.html > At least on Windows there is no difference > to retrieve the date of a file or a directory: Why are you quoting MSDN WinAPI help instead of FreePascal keyword help?

I had a brief look at the code and thought that it would simply hand over the file (directory) name to the API function. In this case it would work the same for files and directories (at least on windows). But I can be wrong.

The FPC docs clearly state the return value is -1 in case of directories. Have you tested it?

No, I haven't tested it. Did you test it?
What is your answer to the original question?
How to get the date of a directory entry?

Reply by email

Rik van Kekem
to Jürgen Hestermann

Maybe it's just me but what's the use of "Date modified" for a folder? It *does not* (like TS expects) reflect the date of the last file *changed* in the folder. Only when files are removed or added the "Date modified" of the folder changes. If you also want the time of the last changes in the folder you would need to loop through all the files.

And how would you handle changes in subfolders? Would you expect FileAge to also include subfolders?

Reply by email

Mark Morgan Lloyd
to Rik van Kekem
Rik van Kekem wrote 5 lines
Maybe it's just me but what's the use of "Date modified" for a folder? It *does not* (like TS expects) reflect the date of the last file *changed* in the folder. Only when files are removed or added the "Date modified" of the folder changes. If you also want the time of the last changes in the folder you would need to loop through all the files.

That of course is a good point, but if [whoever asked the question] was writing an archiver or a file transfer program then his users would assume that it should (i.e. would be reasonably expected to, irrespective of documentation etc.) preserve all the POSIX timestamps, even if their meaning was counter-intuitive.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Richard Mace
to Mark Morgan Lloyd

On 27 October 2014 18:57, Mark Morgan Lloyd <

Show quoted text 16 lines
wrote: Rik van Kekem wrote: > Maybe it's just me but what's the use of "Date modified" for a folder? > It *does not* (like TS expects) reflect the date of the last file > *changed* in the folder. Only when files are removed or added the "Date > modified" of the folder changes. If you also want the time of the last > changes in the folder you would need to loop through all the files. > That of course is a good point, but if [whoever asked the question] was writing an archiver or a file transfer program then his users would assume that it should (i.e. would be reasonably expected to, irrespective of documentation etc.) preserve all the POSIX timestamps, even if their meaning was counter-intuitive.

?Thanks for all of everyones input regarding this. It looks like the solution that I am going to have to use is to scan all of the files within the folder and work out new latest modified file from that.

Thanks again

Richard?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20141028/eb5a2f1f/attachment.html>

Reply by email

Marco van de Voort
to Richard Mace: I can see that we have a "FileAge" function and also a "FileGetDate" however, I was…
Richard Mace wrote
I can see that we have a "FileAge" function and also a "FileGetDate" however, I was wondering what the best way of getting the last modified date of a folder? Effectively, the last time that a file was created/changed within a folder?

On Windows you can access finddata, I did this to get the creation time, but the record has multiple fields:

{$mode delphi}
uses sysutils,windows;
function GetFileInformation(const FileName: string; out FileInfo:
TSearchRec): Boolean;
begin
  Result := FindFirst(FileName, faAnyFile, FileInfo) = 0;
  if Result then
    SysUtils.FindClose(FileInfo);
end;
function GetFileInformation2(const FileName: string): TSearchRec;
begin
  if not GetFileInformation(FileName, Result) then
    RaiseLastOSError;
end;
function GetFileCreation(const FileName: string): TFileTime;
begin
   Result := GetFileInformation2(FileName).FindData.ftCreationTime;
end;

Reply by email