note 73652 deleted from function.readdir by tularis
| From: | tularis@php.net | Date: | Sun, 13 May 2007 18:58:35 +0000 |
| Subject: | note 73652 deleted from function.readdir by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126494@lists.php.net to get a copy of this message | ||
Note Submitter:
----
The previous example has a flaw -- the first 'if' inside the while loop must check if
$skipDots == false, otherwise it will not do what it is intended to do. Here is a corrected version.
function php4_scandir($dir,$listDirectories=false, $skipDots=true) {
$dirArray = array();
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." || $skipDots == false) {
if($listDirectories == false && is_dir($file)) { continue; }
array_push($dirArray,basename($file));
}
}
closedir($handle);
}
return $dirArray;
}