Search code examples
phpglob

PHP glob function to match directories but not files


I am trying to use the PHP function glob() to match directories, not files. I can get it to match all folders using glob('*'), but that matches files also. I can match all files using glob(*.*), but that's not what I want.

Is there a way to subtract perameters from the glob() matching system, or should I use preg_match() to limit the results?


Solution

  • According to the manual:

    GLOB_ONLYDIR - Return only directory entries which match the pattern

    So that would be:

    glob('*', GLOB_ONLYDIR)