note 87527 added to function.scandir
| From: | dsiembab at fullchannel dot net | Date: | Tue, 09 Dec 2008 07:29:58 +0000 |
| Subject: | note 87527 added to function.scandir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-147941@lists.php.net to get a copy of this message | ||
Back in the saddle of scandir I wrote this function for a function that I needed to seperate
directories from files. Since I am still learning from my last example way below I would figure I
would add it so it can be criticized.
<?php
function dirlist($dir, $bool = "dirs"){
$truedir = $dir;
$dir = scandir($dir);
if($bool == "files"){ // dynamic function based on second pram
$direct = 'is_dir';
}elseif($bool == "dirs"){
$direct = 'is_file';
}
foreach($dir as $k => $v){
if(($direct($truedir.$dir[$k])) || $dir[$k] == '.' || $dir[$k] == '..' ){
unset($dir[$k]);
}
}
$dir = array_values($dir);
return $dir;
}
?>
<?php
print_r(dirlist("../")); //confirm array of subdirectories
print_r(dirlist("../", "files") // confirm list on files in the directory
?>
----
Server IP: 64.71.164.2
Probable Submitter: 24.38.173.219
----
Manual Page -- http://www.php.net/manual/en/function.scandir.php
Edit -- https://master.php.net/note/edit/87527
Del: integrated -- https://master.php.net/note/delete/87527/integrated
Del: useless -- https://master.php.net/note/delete/87527/useless
Del: bad code -- https://master.php.net/note/delete/87527/bad+code
Del: spam -- https://master.php.net/note/delete/87527/spam
Del: non-english -- https://master.php.net/note/delete/87527/non-english
Del: in docs -- https://master.php.net/note/delete/87527/in+docs
Del: other reasons-- https://master.php.net/note/delete/87527
Reject -- https://master.php.net/note/reject/87527
Search -- https://master.php.net/manage/user-notes.php