note 29039 added to function.readdir
| From: | php at silisoftware dot com | Date: | Fri, 31 Jan 2003 04:16:24 +0000 |
| Subject: | note 29039 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-43168@lists.php.net to get a copy of this message | ||
Yet another recursive directory listing script. This one returns a list of all absolute filenames
(files only, no directories) in or below the directory first specified in $DirectoriesToScan.
$DirectoriesToScan = array(realpath('.'));
$DirectoriesScanned = array();
while (count($DirectoriesToScan) > 0) {
foreach ($DirectoriesToScan as $DirectoryKey => $startingdir) {
if ($dir = @opendir($startingdir)) {
while (($file = readdir($dir)) !== false) {
if (($file != '.') && ($file != '..')) {
$RealPathName = realpath($startingdir.'/'.$file);
if (is_dir($RealPathName)) {
if (!in_array($RealPathName, $DirectoriesScanned) && !in_array($RealPathName,
$DirectoriesToScan)) {
$DirectoriesToScan[] = $RealPathName;
}
} elseif (is_file($RealPathName)) {
$FilesInDir[] = $RealPathName;
}
}
}
closedir($dir);
}
$DirectoriesScanned[] = $startingdir;
unset($DirectoriesToScan[$DirectoryKey]);
}
}
$FilesInDir = array_unique($FilesInDir);
sort($FilesInDir);
foreach ($FilesInDir as $filename) {
echo $filename."\n";
}
--
http://www.php.net/manual/en/function.readdir.php
http://master.php.net/manage/user-notes.php?action=edit+29039
http://master.php.net/manage/user-notes.php?action=delete+29039
http://master.php.net/manage/user-notes.php?action=reject+29039