note 91218 added to function.scandir
| From: | pocketjpaul at gmail dot com | Date: | Sat, 30 May 2009 20:42:25 +0000 |
| Subject: | note 91218 added to function.scandir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-156188@lists.php.net to get a copy of this message | ||
Just a fix to the ninja's functions:
With this fix there is no notice when $x isn't set, and the function returns an empty array
instead of 'null' if there is no files/dirs: this is usefull when you use foreach on the
result.
<?php
//NNNIIIinnnjaaa::
//array of files without directories... optionally filtered by extension
function file_list($d,$x = null){
$l = array();
foreach(array_diff(scandir($d),array('.','..')) as
$f)if(is_file($d.'/'.$f)&&(($x)?ereg($x.'$',$f):1))$l[]=$f;
return $l;
}
//NNNIIIinnnjaaa::
//array of directories
function dir_list($d){
$l = array();
foreach(array_diff(scandir($d),array('.','..')) as
$f)if(is_dir($d.'/'.$f))$l[]=$f;
return $l;
}
----
Server IP: 89.31.146.176
Probable Submitter: 84.99.150.44
----
Manual Page -- http://www.php.net/manual/en/function.scandir.php
Edit -- https://master.php.net/note/edit/91218
Del: integrated -- https://master.php.net/note/delete/91218/integrated
Del: useless -- https://master.php.net/note/delete/91218/useless
Del: bad code -- https://master.php.net/note/delete/91218/bad+code
Del: spam -- https://master.php.net/note/delete/91218/spam
Del: non-english -- https://master.php.net/note/delete/91218/non-english
Del: in docs -- https://master.php.net/note/delete/91218/in+docs
Del: other reasons-- https://master.php.net/note/delete/91218
Reject -- https://master.php.net/note/reject/91218
Search -- https://master.php.net/manage/user-notes.php