I took a look at recursive searching in PHP (see here), and it's really helped my understanding of what I want to do. However, I'm hitting a minor roadblock.
What I want to do is use this recursive search to return the path of a specific folder name that is in multiple locations. Once that folder name is found, it would execute another function. This would continue until all folders with that name are found.
I have some code from a similar question posted here as a base, but I'm a little confused on how to phrase it as such to "look" for a certain folder name. What is the best way to do that?
An exemple that works (in other words, there is probably a more elegant way to do it):
function myfunction($param) {
echo $param . PHP_EOL;
}
$path = realpath('/myrootpath');
$target = 'myfolder';
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::SELF_FIRST,
RecursiveIteratorIterator::CATCH_GET_CHILD);
foreach($objects as $name => $object){
if (preg_match('~^.+/' . $target .'(?=/\.$)~', $object, $match))
myfunction($match[0]);
}