I have set up a basic script that is posting an array of paths to find template files inside them; currently it\'s only searching two levels deep and I\'m having some troubles g
Universal File search in folder, sub-folder :
function dirToArray($dir,$file_name) {
$result = array();
$cdir = scandir($dir);
foreach ($cdir as $key => $value)
{
if (!in_array($value,array(".","..")))
{
if (is_dir($dir . DIRECTORY_SEPARATOR . $value))
{
$result[$value] = dirToArray($dir . DIRECTORY_SEPARATOR . $value,$file_name);
}
else
{
if($value == $file_name){
$result[] = $value;
}
}
}
}
return $result;
}
define('ROOT', dirname(__FILE__));
$file_name = 'template.html';
$tree = dirToArray(ROOT,$file_name);
echo "".print_r($tree,1)."
";
OUTPUT :
Array
(
[components] => Array
(
[side] => Array
(
[second] => Array
(
[0] => template.html
[third] => Array
(
[0] => template.html
)
)
[0] => template.html
)
[0] => template.html
)
[0] => template.html
)