Hello,
I have modified the file shared and cleverly created by Elmar in the following way.
The modified version, has the option of an additional input argument which is a string. This string represents a pattern to restrict the search to those files with that pattern in their file name. Therefore, the list of subfolders is limited to those that contain files with the given pattern in their file name and also those files if needed. What I did not implemented is a search for subfolders with a name containing the pattern. If needed this can be implemented easily.
If interested, please let me know.