Get all file all subfolders and all hidden file with glob

前端 未结 6 1836
故里飘歌
故里飘歌 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:25

    This returns hidden files and folders, but not . or ..:

    glob($dir . '/{,.}*[!.]', GLOB_MARK | GLOB_BRACE);
    

    Instead of Houmams answer does it return the valid filname ...file.ext as well.

    Tested with $dir="test/" and the following files:

    test/.hiddenfolder/
    test/folder/
    test/...file
    test/...file.ext
    test/.h
    test/.hiddenfile
    test/file
    test/file.ext
    

    Additional information
    Houman tried to target . or .. with [!.,!..], but as this is a character class it is not possible to target strings with a defined length. This means [!.] and [!..] are identical and target both strings not containing an unlimited amount of dots (., .., ..., ...., etc.). Because of that I used [!.] only. Targeting strings is only possible with curly braces like {jpg,png}. You find a good explanation in the php.net comments.

提交回复
热议问题