note 126663 added to function.scandir
| From: | coolbikram0 at gmail dot com | Date: | Sat, 04 Dec 2021 05:53:56 +0000 |
| Subject: | note 126663 added to function.scandir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217329@lists.php.net to get a copy of this message | ||
A simple recursive function to list all files and subdirectories in a directory:
<?php
function listAllFiles($dir) {
$array = array_diff(scandir($dir), array('.', '..'));
foreach ($array as &$item) {
$item = $dir . $item;
}
unset($item);
foreach ($array as $item) {
if (is_dir($item)) {
$array = array_merge($array, listAllFiles($item . DIRECTORY_SEPARATOR));
}
}
return $array;
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 2401:4900:1261:a125:347d:b09c:6483:f017)
----
Manual Page -- https://php.net/manual/en/function.scandir.php
Edit -- https://main.php.net/note/edit/126663
Del: integrated -- https://main.php.net/note/delete/126663/integrated
Del: useless -- https://main.php.net/note/delete/126663/useless
Del: bad code -- https://main.php.net/note/delete/126663/bad+code
Del: spam -- https://main.php.net/note/delete/126663/spam
Del: non-english -- https://main.php.net/note/delete/126663/non-english
Del: in docs -- https://main.php.net/note/delete/126663/in+docs
Del: other reasons-- https://main.php.net/note/delete/126663
Reject -- https://main.php.net/note/reject/126663
Search -- https://main.php.net/manage/user-notes.php