note 113903 added to function.scandir
| From: | donovan dot pp at gmail dot com | Date: | Mon, 16 Dec 2013 03:42:28 +0000 |
| Subject: | note 113903 added to function.scandir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-197945@lists.php.net to get a copy of this message | ||
Non-recursive way (red: FASTER & less memory consumption) to list all directory content :
<?php
function list_directory($dir) {
$file_list = array();
$stack[] = $dir;
while ($stack) {
$current_dir = array_pop($stack);
if ($dh = opendir($current_dir)) {
while (($file = readdir($dh)) !== false) {
if ($file !== '.' AND $file !== '..') {
$current_file = "{$current_dir}/{$file}";
$report = array();
if (is_file($current_file)) {
$file_list[] = "{$current_dir}/{$file}";
} elseif (is_dir($current_file)) {
$stack[] = $current_file;
$file_list[] = "{$current_dir}/{$file}/";
}
}
}
}
}
return $file_list;
}
// usage :
//print_r(list_directory('C:/'));
//print_r(list_directory('C:/Users'));
print_r(list_directory('/var/www'));
?>
----
Server IP: 72.52.91.14
Probable Submitter: 72.52.91.14
----
Manual Page -- http://php.net/manual/en/function.scandir.php
Edit -- https://master.php.net/note/edit/113903
Del: integrated -- https://master.php.net/note/delete/113903/integrated
Del: useless -- https://master.php.net/note/delete/113903/useless
Del: bad code -- https://master.php.net/note/delete/113903/bad+code
Del: spam -- https://master.php.net/note/delete/113903/spam
Del: non-english -- https://master.php.net/note/delete/113903/non-english
Del: in docs -- https://master.php.net/note/delete/113903/in+docs
Del: other reasons-- https://master.php.net/note/delete/113903
Reject -- https://master.php.net/note/reject/113903
Search -- https://master.php.net/manage/user-notes.php