I am trying to find all html files within directories in a root directory, I have an array with all the directories in and I'm trying to loop through each directory in the array to find the files and create a list but it is not working, any ideas?
$dirs = glob("/Root_directory*", GLOB_ONLYDIR);
foreach($dirs as $dir) {
$phpfiles = glob($dir . "*.html");
foreach($phpfiles as $phpfile) {
echo "<a href=$phpfile>".basename($phpfile)."</a>";
}
}
I also tried the approach recommended here using recursion and this gave an empty array
$Directory = new RecursiveDirectoryIterator('path/to/project/');
$Iterator = new RecursiveIteratorIterator($Directory);
$Regex = new RegexIterator($Iterator, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);