Problem recursively building array
| From: | Chris Hobbs | Date: | Wed, 26 Sep 2001 18:38:28 +0000 |
| Subject: | Problem recursively building array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-68905@lists.php.net to get a copy of this message | ||
I'm attempting to build an array of filenames in a sub-directory with sub-directories. I'm using a modified version of code found on php.net - the function I wrote is here:
function getDirList ($dirName) {
$dirList=array();
$d = dir($dirName);
while ($entry = $d->read()) {
if ($entry != "." && $entry != "..") {
if (is_dir($dirName."/".$entry)) {
echo "<b>Directory found: $entry</b><br>\n";
$dirList = $dirList + getDirList($dirName."/".$entry);
} else {
$temp = $dirName."/".$entry;
$temp = str_replace("/var/www/html/boarddocs/", "", $temp);
echo $temp."<br>\n";
$dirList[] = $temp;
}
}
}
return $dirList;
}
It's called with: $bplist = getDirList($bppath);
$bppath is correct.
The problem is that although my testing of the function shows all of the entries correctly (note the 'echo $temp' line), not all of these entries are ending up in the array - in fact, large chunks of some directories, and all of other directories, are missing.
Sample output is here: http://www.silvervalley.k12.ca.us/boarddocs/bpar.php
Complete code is here: http://www.silvervalley.k12.ca.us/boarddocs/bpar.phps
I'm gonna be real annoyed if I missed something stupid. I built as much debugging output into this as I thought I should, but your help will be appreciated.
--
_______ ___ _ ____ _____
Chris Hobbs / ____\ \ / / | | |/ ___\| __ \
Head Geek | (___ \ \ / /| | | | (___ | | | |
WebMaster \___ \ \ \/ / | | | |\___ \| | | |
PostMaster ____) | \ / | |__| |____) | |__| |
\____/ \/ \____/ \____/|_____/
http://www.silvervalley.k12.ca.us
chobbs@silvervalley.k12.ca.us