Question: why FileTools:-ListDirectory does not work when suing select and depth=infinity?

I wanted to search for all files with some extention in directory tree. But when adding depth=infinity and also adding 'select'="*.log" (or whatever the extension I want is), then it returns an empty list even though there are files with this extension but deep in the tree.

If I remove select, then it does work, but it returns list of the files in the tree. Which I do not want. I want to filter these by select.

If I remove depth=infinity then select works but only finds such files at top level of the directory and does look down the tree where there are more such files.

It seems select and depth conflict with each others.  Adding 'all' option makes no difference.

I do not remember now if I reported this before or not.

Here is worksheet showing this problem

interface(version);

`Standard Worksheet Interface, Maple 2025.0, Linux, March 24 2025 Build ID 1909157`

folder_name:="/home/me/maple2025"; #fails to find all such files
FileTools:-ListDirectory(folder_name,'select'="*.wav",depth=infinity);

"/home/me/maple2025"

[]

folder_name:="/home/me/maple2025"; #works but only top level
FileTools:-ListDirectory(folder_name,'select'="*.log");

"/home/me/maple2025"

["Maple_2025_Install_2025_04_03_12_34_10.log"]

folder_name:="/home/me/maple2025"; #works but this finds everything
FileTools:-ListDirectory(folder_name,depth=infinity);

"/home/me/maple2025"

`[Length of output exceeds limit of 10000]`

 


 

Download listdirectory_may_3_2025.mw

How can one get list of files with specific extension in the whole tree? And why is adding select makes it not work? Help does not say anything about select does not work when adding depth=infinity.

I suppose I can get list of all files in tree, then iterate over the list and remove all entries that do not end with the extension I wanted. But this is what select is supposed to do. For example

folder_name:="/home/me/maple2025/"; #works but this finds everything
L:=FileTools:-ListDirectory(folder_name,depth=infinity):
map(X->`if`(FileTools:-Extension(X)="wav",X,NULL),L);

Gives list of only files with extension "wav". So the above is workaround for now.

Please Wait...