note 89839 deleted from function.readdir by danbrown

From: Date: Wed, 25 Mar 2009 17:06:56 +0000
Subject: note 89839 deleted from function.readdir by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-152433@lists.php.net to get a copy of this message
Note Submitter: corey at eyewantmedia dot com ---- If anyone is interested, this works pretty well in 5.0 and it is short. <?php function GetDirectoryContentsRecursive($dir, $showDirs = false, $regex=null) { $path = realpath($dir); $res = array(); $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST); //Unfortunately array_keys does not work on iterator objects, so we have to loop to make meaningful results foreach($objects as $name => $object){ if($showDirs || !is_dir($name) ) { // It will only check the second check if the first one is false, so no need to specify that $showDirs is false if(empty($regex) || preg_match($regex, $name) == 1 ) { $res[] = $name; } } } return $res; } ?>

« previous php.notes (#152433) next »