note 90278 deleted from function.glob by danbrown
| From: | danbrown@php.net | Date: | Thu, 03 Dec 2009 14:13:45 +0000 |
| Subject: | note 90278 deleted from function.glob by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-163537@lists.php.net to get a copy of this message | ||
Note Submitter: me at lx dot sg
----
Referring to the recursive glob() function below
(http://sg.php.net/manual/en/function.glob.php#87221):
It does not work when the pattern contains a directory name. Here's a fixed version:
<?php
function rglob($pattern, $flags = 0, $path = '') {
if (!$path && ($dir = dirname($pattern)) != '.') {
if ($dir == '\\' || $dir == '/') $dir = '';
return rglob(basename($pattern), $flags, $dir . '/');
}
$paths = glob($path . '*', GLOB_ONLYDIR | GLOB_NOSORT);
$files = glob($path . $pattern, $flags);
foreach ($paths as $p) $files = array_merge($files, rglob($pattern, $flags, $p . '/'));
return $files;
}
?>