note 30238 added to function.glob
| From: | sthomas at townnews dot com | Date: | Tue, 11 Mar 2003 21:41:30 +0000 |
| Subject: | note 30238 added to function.glob | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-45116@lists.php.net to get a copy of this message | ||
/**
* Recursive version of glob
*
* @return array containing all pattern-matched files.
*
* @param string $sDir Directory to start with.
* @param string $sPattern Pattern to glob for.
* @param int $nFlags Flags sent to glob.
*/
function rglob($sDir, $sPattern, $nFlags = NULL)
{
$sDir = escapeshellcmd($sDir);
// Get the list of all matching files currently in the
// directory.
$aFiles = glob("$sDir/$sPattern", $nFlags);
// Then get a list of all directories in this directory, and
// run ourselves on the resulting array. This is the
// recursion step, which will not execute if there are no
// directories.
foreach (glob("$sDir/*", GLOB_ONLYDIR) as $sSubDir)
{
$aSubFiles = rglob($sSubDir, $sPattern, $nFlags);
$aFiles = array_merge($aFiles, $aSubFiles);
}
// The array we return contains the files we found, and the
// files all of our children found.
return $aFiles;
}
--
http://www.php.net/manual/en/function.glob.php
http://master.php.net/manage/user-notes.php?action=edit+30238
http://master.php.net/manage/user-notes.php?action=delete+30238
http://master.php.net/manage/user-notes.php?action=reject+30238