Jump to content

recursive glob ?


Recommended Posts

From the glob site at php.net a user contribution:


Contributed by php at hm2k.org

// $Id: rglob.php,v 1.0 2008/11/24 17:20:00 hm2k Exp $

* Recursive glob()

* @param int $pattern
*  the pattern passed to glob()
* @param int $flags
*  the flags passed to glob()
* @param string $path
*  the path to scan
* @return mixed
*  an array of files in the given path matching the pattern.

function rglob($pattern='*', $flags = 0, $path='')
    $paths=glob($path.'*', GLOB_MARK|GLOB_ONLYDIR|GLOB_NOSORT);
    $files=glob($path.$pattern, $flags);
    foreach ($paths as $path) { $files=array_merge($files,rglob($pattern, $flags, $path)); }
    return $files;

/* example usage: */


Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.