Map the directory tree given by the directory parameter.
public mapTreeMultiple ( string $directory, integer $maxrecursion, $count ) : array | ||
$directory | string | contains the directory path that you want to map. |
$maxrecursion | integer | maximun number of folders to recursive map |
Résultat | array | a multidimensional array containing all subdirectories and their files. For example: Array ( [0] => file_1.php [1] => file_2.php [subdirname] => Array ( [0] => file_1.php ) ) |
/** * Map the directory tree given by the directory parameter. * * @param string $directory contains the directory path that you * want to map. * @param integer $maxrecursion maximun number of folders to recursive * map * * @return array a multidimensional array containing all subdirectories * and their files. For example: * * Array * ( * [0] => file_1.php * [1] => file_2.php * [subdirname] => Array * ( * [0] => file_1.php * ) * ) * * @author Mika Tuupola <*****@*****.**> * @access public * @static */ function &mapTreeMultiple($directory, $maxrecursion = 0, $count = 0) { $retval = array(); $count++; /* strip trailing slashes */ $directory = preg_replace('![\\\\/]+$!', '', $directory); if (is_readable($directory)) { $dh = opendir($directory); while (false !== ($entry = @readdir($dh))) { if ($entry != '.' && $entry != '..') { array_push($retval, $entry); } } closedir($dh); } sort($retval); while (list($key, $val) = each($retval)) { if (!is_array($val)) { $path = $directory . "/" . $val; if (is_dir($path)) { unset($retval[$key]); if ($maxrecursion == 0 || $count < $maxrecursion) { $retval[$val] =& File_Find::mapTreeMultiple($path, $maxrecursion, $count); } } } } return $retval; }
/** * Map the directory tree given by the directory parameter. * * @param string $directory contains the directory path that you * want to map. * @param integer $maxrecursion maximun number of folders to recursive * map * * @return array a multidimensional array containing all subdirectories * and their files. For example: * * Array * ( * [0] => file_1.php * [1] => file_2.php * [subdirname] => Array * ( * [0] => file_1.php * ) * ) * * @author Mika Tuupola <*****@*****.**> * @access public * @static */ function &mapTreeMultiple($directory, $maxrecursion = 0, $count = 0) { $retval = array(); $count++; $directory .= DIRECTORY_SEPARATOR; $dh = opendir($directory); while (false !== ($entry = @readdir($dh))) { if ($entry != '.' && $entry != '..') { array_push($retval, $entry); } } closedir($dh); while (list($key, $val) = each($retval)) { $path = $directory . $val; $path = str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $path); if (!is_array($val) && is_dir($path)) { unset($retval[$key]); if ($maxrecursion == 0 || $count < $maxrecursion) { $retval[$val] =& File_Find::mapTreeMultiple($path, $maxrecursion, $count); } } } return $retval; }
/** * Delete language files for the given language. * @param string $p_languageCode * @return mixed * Return TRUE on success, PEAR_Error on failure. */ public static function DeleteLanguageFiles($p_languageCode) { global $g_localizerConfig; $langDir = $g_localizerConfig['TRANSLATION_DIR'].'/'.$p_languageCode; if (!file_exists($langDir)) { return true; } $files = File_Find::mapTreeMultiple($langDir, 1); foreach ($files as $fileName) { $pathname = $langDir . DIR_SEP . $fileName; if (file_exists($pathname)) { if (is_writable($pathname)) { unlink($pathname); } else { return new PEAR_Error(camp_get_error_message(CAMP_ERROR_DELETE_FILE, $pathname), CAMP_ERROR_DELETE_FILE); } } } @rmdir($langDir); return true; } // fn DeleteLanguageFiles