I am building a site which has a "gallery" folder with images. Inside the "gallery" folder there are other sub-folders, one for each image category. For example:
gallery
|---foo
|---bar
|---cat
Inside these folders there are some images among the others that their name starts with "slideshow_".
I want to write a script that searches all folders inside "gallery" and assign their path in an array variable. The names and the number of sub-folders should be considered unknown.
I know how to do it by hardcoding names and merging the results from glob('gallery/{name}/slideshow_*')
but I want something better, preferrably with SPL. I have tried this with no success:
$dir = new RecursiveDirectoryIterator('assets/img/gallery');
foreach (new RecursiveIteratorIterator($dir) as $filename => $file) {
$slideshow_images[] = glob('slideshow_*');
}
If you could use Symfony Finder, this is a breeze:
use Symfony\Component\Finder\Finder;
$finder = new Finder();
$finder->files()->in('assets/img/gallery')->name('slideshow_*');
foreach ($finder as $file) {
// Do magic here
}