Kategorien
PHP Server

rekursive php glob funktion – ordner/dateien rekursiv nach pattern filtern


protected function rGlob($pattern = '*', $flags = 0, $path = false)
{
    if (!$path)
    {
        $path = dirname($pattern).DIRECTORY_SEPARATOR;
    }

    $pattern    = basename($pattern);
    $paths      = glob($path.'*', GLOB_MARK|GLOB_ONLYDIR|GLOB_NOSORT);
    $files      = glob($path.$pattern, $flags);
    foreach ($paths as $path)
    {
        $files = array_merge($files, $this->rGlob($pattern, $flags, $path));
    }
    return $files;
}