File_Find::mapTreeMultiple()

From: Date: Sat, 16 Feb 2002 19:54:54 +0000
Subject: File_Find::mapTreeMultiple()
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-4750@lists.php.net to get a copy of this message
I have made a small addition to File_Find class waiting for commit. Added was a new mapTreeMultiple() function which reads contents of given directory and its subdirectories and returns an multidimensional array looking like the example below. Does anyone have anything against of committing this? Array ( [0] => document_1.doc [1] => document_2.doc [2] => document_3.doc [subfolder_1] => Array ( [0] => document_1.doc [1] => document_2.doc [2] => document_2.doc ) [subfolder_2] => Array ( [0] => document_1.doc [1] => document_2.doc [2] => document_2.doc [subfolder_2_1] => Array ( [0] => document_1.doc [1] => document_2.doc [2] => document_2.doc ) ) ) -cut- /** * Map the directory tree given by the directory parameter. * * @param string $directory contains the directory path that you * want to map. * * @return array a multidimensional array containing all subdirectories * and their files * * @author Mika Tuupola <tuupola@appelsiini.net> * @access public */ function &mapTreeMultiple($directory) { $retval = array(); $directory .= '/'; $dh=opendir($directory); while ($entry = readdir($dh)) { if ($entry != "." && $entry != "..") { array_push($retval, $entry); } } closedir($dh); while (list($key, $val) = each($retval)) { $path = $directory . $val; $path = str_replace("//","/",$path); if (!(is_array($val))) { if (is_dir($path)) { unset($retval[$key]); $retval[$val] = File_Find::mapTreeMultiple($path); } } } return($retval); } -cut- -- Mika Tuupola http://www.appelsiini.net/~tuupola/

« previous php.pear.dev (#4750) next »