James30263 James30263 - 1 year ago 100
CSS Question

How can I find CSS files Recursively?

Is there a way for me to search for css files recursively using the following code?

The directory I'm searching is "themes/Evolution". I want it to search for css files in the sub-directories as well.


// Does not support flag GLOB_BRACE
function rglob($pattern, $flags = 0) {
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
$files = array_merge($files, rglob($dir.'/'.basename($pattern), $flags));
return $files;


Answer Source

Try this:

$directoryWhereToSearch = 'themes/Evolution';
$allFiles = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directoryWhereToSearch));
$cssFiles = new RegexIterator($allFiles, '/\.css$/i');
foreach ($cssFiles as $cssFile) {
    echo $cssFile->getFilename();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download