Does glob() have negation?

前端 未结 5 1780
执念已碎
执念已碎 2020-12-10 13:47

I know I can do this...

glob(\'/dir/somewhere/*.zip\');

...to get all files ending in .zip, but is there a way to return all f

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-10 14:21

    A quick way would be to glob() for everything and use preg_grep() to filter out the files that you do not want.

    preg_grep('#\.zip$#', glob('/dir/somewhere/*'), PREG_GREP_INVERT)
    

    Also see Glob Patterns for File Matching in PHP

提交回复
热议问题