note 34563 added to function.readdir
| From: | ftrudeau at rack1 dot php dot net | Date: | Wed, 30 Jul 2003 22:43:53 +0000 |
| Subject: | note 34563 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-53038@lists.php.net to get a copy of this message | ||
I really liked the little script posted at 04-Jan-2003 04:34. Problem is, I needed it to be able to
search for dirrectories also. See here we are ... the equivalent of
find $path -type f,
find $path -type d or a merge of both ... Hope it pleases someone else then me =)
$files = walk_dir($path, 'files');
$dirs = walk_dir($path, 'dirs');
$both = walk_dir($path, 'both');
function walk_dir($path, $get = 'both') {
if ($dir = opendir($path)) {
while (false !== ($file = readdir($dir))) {
if (is_dir($path . '/' . $file) && ($file !=
'.') && ($file != '..')) {
if ($get == 'dirs' || $get == 'both') {
$retval[] = $path . '/' . $file;
}
$retval = array_merge($retval, walk_dir($path . '/' .
$file));
} else if (is_file($path . '/' . $file)) {
if ($get == 'files' || $get == 'both') {
$retval[] = $path . '/' . $file;
}
}
}
closedir($dir);
}
return $retval;
}
----
Manual Page -- http://www.php.net/manual/en/function.readdir.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34563
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34563&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34563&report=yes