Get all file all subfolders and all hidden file with glob

前端 未结 6 1843
故里飘歌
故里飘歌 2020-12-17 23:28

In my recurive function to zip a whole folders i have this piece of code glob($path. \'/*\') that give me all files and subfolders matching my $path.

Here I read

6条回答
  •  死守一世寂寞
    2020-12-18 00:24

    Probably you've found already the solution, but in case you were looking for a way that gives you the files and directories, recursively and taking care of hidden files, this was what I got:

    function rglob($pattern, $flags = 0) {
        $files = glob($pattern, $flags);
    
        foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
            $files = array_merge($files, $this->rglob($dir.'/'.basename($pattern), $flags));
        }
    
        return $files;
    }
    

提交回复
热议问题