function globr($dir, $pattern) { $files = glob($dir . '/' . $pattern); foreach (glob($dir . '/*', GLOB_ONLYDIR) as $subdir) { $subfiles = globr($subdir, $pattern); $files = array_merge($files, $subfiles); } return $files; }
function globr($sDir, $sPattern, $nFlags = NULL) { $sDir = escapeshellcmd($sDir); $aFiles = glob("{$sDir}/{$sPattern}", $nFlags); foreach (glob("{$sDir}/*", GLOB_ONLYDIR) as $sSubDir) { $aSubFiles = globr($sSubDir, $sPattern, $nFlags); $aFiles = array_merge($aFiles, $aSubFiles); } return $aFiles; }
/** * Return array of files matched, decending into subdirectories */ function globr($dir, $pattern) { $dir = escapeshellcmd($dir); // list of all matching files currently in the directory. $files = glob("{$dir}/{$pattern}"); // get a list of all directories in this directory foreach (glob("{$dir}/*", GLOB_ONLYDIR) as $subdir) { $subfiles = globr($subdir, $pattern); $files = array_merge($files, $subfiles); } return $files; }
function testAll() { $files = globr(dirname(__FILE__) . '/csst', '*.csst'); foreach ($files as $filename) { $expectation = new csstidy_csst(); $result = $this->assert($expectation, $filename, '%s'); // this is necessary because SimpleTest doesn't support // HTML messages; this probably should be in the reporter. // This is *not* compatible with XmlReporter if (!$result) { echo $expectation->render(); } } }
/** * 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 globr($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 = globr($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; }
/** * Returns files & directories in a given directory recursively. * * Returned array is flattened - both keys and values are full filesystem paths. * * Faster than scandirr(), but can consume lots of resources if used * excessively with deep recursion. * * Uses glob marking with substr() to check for subdirectories, which runs * about twice as fast as the same function using is_dir() * * @param string $dir Directory to scan. * @param int $levels Max directory depth level. * @param array &$glob The glob of flattend paths. * @param int $level Current directory level. Used interally. * @return array Flattened assoc. array of filepaths. */ function globr($dir, $levels = 5, array &$glob = array(), $level = 0) { $dir = rtrim($dir, '/\\') . '/*'; foreach (glob($dir, GLOB_MARK) as $item) { if ($level < $levels && DIRECTORY_SEPARATOR === substr($item, -1)) { $level++; globr($item, $levels, $glob, $level); } else { $glob[$item] = $item; } } return $glob; }