Re: [Lazarus] Getting the last modified date of a directory

2014-10-26 Thread Jürgen Hestermann


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
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Getting the last modified date of a directory

2014-10-26 Thread 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

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Getting the last modified date of a directory

2014-10-26 Thread Richard Mace
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
On 26 Oct 2014 09:11, "Jürgen Hestermann"  wrote:

>
> 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
> Lazarus@lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
>
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Getting the last modified date of a directory

2014-10-26 Thread Jürgen Hestermann


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:
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.



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Getting the last modified date of a directory

2014-10-26 Thread Jürgen Hestermann


Am 2014-10-26 um 10:42 schrieb Richard Mace:


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.



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Getting the last modified date of a directory

2014-10-26 Thread Reinier Olislagers
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?

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


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Getting the last modified date of a directory

2014-10-27 Thread Jürgen Hestermann

Am 2014-10-26 um 11:56 schrieb Reinier Olislagers:
> 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?


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Getting the last modified date of a directory

2014-10-27 Thread Rik van Kekem

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?



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Getting the last modified date of a directory

2014-10-27 Thread Mark Morgan Lloyd

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.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Getting the last modified date of a directory

2014-10-27 Thread Richard Mace
On 27 October 2014 18:57, Mark Morgan Lloyd  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​
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Getting the last modified date of a directory

2014-12-27 Thread Marco van de Voort
On Sat, Oct 25, 2014 at 06:19:07PM +0100, 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;


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus