Re: [fpc-pascal] Getting size of file without opening it?

2020-07-24 Thread Bo Berglund via fpc-pascal
On Fri, 24 Jul 2020 00:29:10 +0200 (CEST), Michael Van Canneyt
 wrote:

>
>
>On Fri, 24 Jul 2020, Bo Berglund via fpc-pascal wrote:
>
>> I am using FindAllFiles in order to list the files in a directory and
>> it works fine.
>>
>> But I also need the size and timestamp of the file so I searched the
>> net for it.
>>
>> What I found was:
>>
>> var T: TDateTime;
>> T := FileDateTodateTime(FileAge(filename));
>>
>> But FileSize() needs a file argument to an open file!
>>
>> This is not what I want, I may not even be allowed to open the file.
>>
>> So is there a *cross-platform* way to retrieve the size of the files
>> too?
>
>uses sysutils;
>
>Function GetFileSize(aFileName : String) : Int64;
>
>Var
>   Info : TSearchRec;
>
>begin
>   If FindFirst(aFileName,0,Info)=0 then
> Result:=Info.SIze
>   else
> Result:=-1;
>   FindClose(Info);
>end;
>
Added to my "utils" unit. :-)
Thanks!

-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] Is there a FindAllDirs command like FindAllFiles?

2020-07-24 Thread Bo Berglund via fpc-pascal
I am using FindAllFiles() in order to enumerate the files of a certain
name pattern in a FPC application on Linux.
I am using Fpc 3.0.4 and Lazarus 2.0.8.

FindAllFiles() has a switch to search the files in subdirectories and
this works fine.

But I would like to enumerate the subdirectories themselves (without
the content). Is there a hidden switch for this or is there a command
to enumerate only the directories of a certain path?
Maybe a way to specify the SearchMask such that it only finds
directories?

According to the FPC wiki FindAllFiles() last argument DirAttr is set
by default to faDirectory, but there is no discussion in the article
on how it can be set to something else and what will be the result in
such a case.

-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal