note 89839 added to function.readdir
| From: | corey at eyewantmedia dot com | Date: | Wed, 25 Mar 2009 17:03:34 +0000 |
| Subject: | note 89839 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152430@lists.php.net to get a copy of this message | ||
If anyone is interested, this works pretty well in 5.0 and it is short.
<?php
function GetDirectoryContentsRecursive($dir, $showDirs = false, $regex=null) {
$path = realpath($dir);
$res = array();
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path),
RecursiveIteratorIterator::SELF_FIRST);
//Unfortunately array_keys does not work on iterator objects, so we have to loop to make meaningful
results
foreach($objects as $name => $object){
if($showDirs || !is_dir($name) ) { // It will only check the second check if the first one is
false, so no need to specify that $showDirs is false
if(empty($regex) || preg_match($regex, $name) == 1 ) {
$res[] = $name;
}
}
}
return $res;
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 70.164.23.92
----
Manual Page -- http://www.php.net/manual/en/function.readdir.php
Edit -- https://master.php.net/note/edit/89839
Del: integrated -- https://master.php.net/note/delete/89839/integrated
Del: useless -- https://master.php.net/note/delete/89839/useless
Del: bad code -- https://master.php.net/note/delete/89839/bad+code
Del: spam -- https://master.php.net/note/delete/89839/spam
Del: non-english -- https://master.php.net/note/delete/89839/non-english
Del: in docs -- https://master.php.net/note/delete/89839/in+docs
Del: other reasons-- https://master.php.net/note/delete/89839
Reject -- https://master.php.net/note/reject/89839
Search -- https://master.php.net/manage/user-notes.php