note 79448 added to class.dir
| From: | jennevdmeer at zonnet dot nl | Date: | Wed, 28 Nov 2007 07:41:15 +0000 |
| Subject: | note 79448 added to class.dir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-132610@lists.php.net to get a copy of this message | ||
Unlike the others here I've created a function that returns the directory's in a
2-dimensional array. Starting from the requested dir:
<?php
/*
getDirTree(string $dir [, bool $showfiles]);
$dir of the folder you want to list, be sure to have an ending /
$showfiles set to 'false' if files shouldnt be listed in the output array
*/
function getDirTree($dir,$p=true) {
$d = dir($dir);$x=array();
while (false !== ($r = $d->read())) {
if($r!="."&&$r!=".."&&(($p==false&&is_dir($dir.$r))||$p==true))
{
$x[$r] = (is_dir($dir.$r)?array():(is_file($dir.$r)?true:false));
}
}
foreach ($x as $key => $value) {
if (is_dir($dir.$key."/")) {
$x[$key] = getDirTree($dir.$key."/",$p);
}
}
ksort($x);
return $x;
}
?>
Example Output:
Array
(
[folder1] => Array
(
[subfolder1] => Array()
[subfolder2] => Array()
[text.txt] => 1
)
[folder2] => Array()
[folder3] => Array
(
[text.txt] => 1
)
)
----
Server IP: 83.137.20.135
Probable Submitter: 213.17.76.118
----
Manual Page -- http://www.php.net/manual/en/class.dir.php
Edit -- https://master.php.net/note/edit/79448
Del: integrated -- https://master.php.net/note/delete/79448/integrated
Del: useless -- https://master.php.net/note/delete/79448/useless
Del: bad code -- https://master.php.net/note/delete/79448/bad+code
Del: spam -- https://master.php.net/note/delete/79448/spam
Del: non-english -- https://master.php.net/note/delete/79448/non-english
Del: in docs -- https://master.php.net/note/delete/79448/in+docs
Del: other reasons-- https://master.php.net/note/delete/79448
Reject -- https://master.php.net/note/reject/79448
Search -- https://master.php.net/manage/user-notes.php