note 42590 deleted from function.readdir by hsc

From: Date: Mon, 06 Mar 2006 19:00:12 +0000
Subject: note 42590 deleted from function.readdir by hsc
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-104923@lists.php.net to get a copy of this message
Note Submitter: paulg at i (hyphen) labs dot co dot uk ---- Simplified recursive directory listing. Returns FolderListing object which contains an array with all the directories and files. <?php class FolderListing { var $newarr = array(); function loop($stack) { if(count($stack) > 0) { $arr = array(); foreach($stack as $key => $value) { array_push($this->newarr, $stack[$key]); if ($dir = @opendir($stack[$key])) { while (($file = readdir($dir)) !== false) { if (($file != '.') && ($file != '..')) { array_push($arr, $stack[$key].'/'.$file); } } } closedir($dir); } $this->loop($arr); } else { $sorted = sort($this->newarr); return($sorted); } } } $start = new FolderListing; $base = array("baseDir"); $start->loop($base); foreach($start->newarr as $value) { echo $value."<br />"; } ?> Add the following code around the array_push line to just check for directories: if(is_dir($stack[$key].'/'.$file)) { }

« previous php.notes (#104923) next »