Sign in Join

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

Mailing lists / fpc-pascal / 2020-07

Is there a FindAllDirs command like FindAllFiles?

4 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

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

Bo Berglund

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

Reply by email

Bart
to Bo Berglund
AM Bo Berglund wrote
But I would like to enumerate the subdirectories themselves (without the content).

Take a look at how FindAllFiles is implemented.
It should be relatively easy to modify it so that it discards files and only adds folders to the list.

Bart

Bart

Reply by email

Bo Berglund
to Bart
Bart wrote 10 lines
On Sat, Jul 25, 2020 at 12:24 AM Bo Berglund via fpc-pascal wrote: > But I would like to enumerate the subdirectories themselves (without > the content). Take a look at how FindAllFiles is implemented. It should be relatively easy to modify it so that it discards files and only adds folders to the list.

I already looked there but it just sends me deeper yet until I do not follow the logic anymore...
Here is what I get when I look at the definition:

procedure FindAllFiles(AList: TStrings; const SearchPath: String;
  SearchMask: String; SearchSubDirs: Boolean; DirAttr: Word);
var
  Searcher: TListFileSearcher;
begin
  Searcher := TListFileSearcher.Create(AList);
  Searcher.DirectoryAttribute := DirAttr;
  try
    Searcher.Search(SearchPath, SearchMask, SearchSubDirs);
  finally
    Searcher.Free;
  end;
end;

The item that is not described in the documentation is the argument "DirAttr" as I mentioned, can that be used for this problem?

I still do not understand what it does since it is not described in the documentation either:

https://wiki.freepascal.org/FindAllFiles

Meanwhile I found a sysutils function: GetDirs()

https://www.freepascal.org/docs-html/rtl/sysutils/getdirs.html

But this uses arrays of PChar where I want to populate a TStrings list.

Bo Berglund Developer in Sweden

Reply by email