I am trying to write a recursive funciton that will produce an array of pdf filepaths within a directory and all its subdirectories. This is what I have so far:
function getPDFArray($dirPath) {
$list = array();
$dir = opendir($dirPath);
$cnt = 0;
while ($file = readdir($dir)) {
$cnt++;
$curFile = $dirPath . '/' . $file;
//echo $curFile;
if (is_file($curFile) && eregi("pdf$", $file)) {
array_push($list, array($curFile, date("Y/m/d", filemtime($curFile))));
}
elseif (is_dir($curFile) && ($file != ".") && ($file != "..")) {
array_push($list, array("DIR>> " . $curFile, ""));
$list += getPDFArray($curFile);
}
}
echo "Number in directory, $dirPath: " . $cnt . "<br />";
return $list;
//$files = scandir(
closedir($dir);
}
It seems to work, kind of. It will list a lot of the files even a lot of file one or two directories down. But It is not getting ALL of them. In one folder, it gets the first file, but none of the rest. In another, it will get them all. And yet in another, it gets none. Any suggestions??
Peter, IDFL
webmaster@idfl.com