Possible Duplicate:
Caching readdir()
I have my site set up so that I have clean URLs and the files themselves are in various levels of folders. To manage it, I have the following script to direct my include farther down in the page.
function listFolderFiles($dir,$exclude){
global $flist;
$ffs = scandir($dir);
foreach($ffs as $ff)
{
if(is_array($exclude) and !in_array($ff,$exclude))
{
if($ff != '.' && $ff != '..')
{
if(!is_dir($dir.'/'.$ff))
{
}
if(is_dir($dir.'/'.$ff))
{
listFolderFiles($dir.'/'.$ff,$exclude);
}
if((is_dir($dir.'/'.$ff)) != 1 && strtolower(substr($ff, strrpos($ff, '.') + 1)) == 'php')
{
$name = basename($ff, ".php");
$flist[] .= $name;
}
}
}
}
}
listFolderFiles('content/',array('filelist.php'));
$removing = array('_en','_es');
$pages = str_replace($removing, "", $flist);
unset($dir, $exclude, $flist);
listFolderFiles('content/Beginner/',array('filelist.php'));
$removing = array('_en','_es');
$beginner = str_replace($removing, "", $flist);
unset($dir, $exclude, $flist);
listFolderFiles('content/Intermediate/',array('filelist.php', $beginner));
$removingi = array('_en','_es');
$intermediate = str_replace($removingi, "", $flist);
unset($dir, $exclude, $flist);
listFolderFiles('content/Advanced/',array('filelist.php', $beginner));
$removinga = array('_en','_es');
$advanced = str_replace($removinga, "", $flist);
Is there a faster way to execute this code, as it is currently used on every pageload, and I only need to update it when I add a new file.