This function returns a recursive list of all subdirectories from a given directory
@access public
- Parameters
-
string | $directory | from this dir the recursion will start. |
bool | $show_hidden | (optional): if set to TRUE also hidden dirs (.dir) will be shown. |
int | $recursion_deep | (optional): An optional integer to test the recursions-deep at all. |
array | $aList | (optional): A simple storage list for the recursion. |
string | $ignore | (optional): This is the part of the "path" to be "ignored" |
- Returns
- array
assume you are looking for directories like: /srv/www/htdocs/lepton/upload/media/a/b/c/ /srv/www/htdocs/lepton/upload/media/a/b/d/
$aEmptyList = []; $skipPathComponent = LEPTON_PATH.MEDIA_DIRECTORY.DIRECTORY_SEPARATOR; $aAll = directory_list( LEPTON_PATH.MEDIA_DIRECTORY, false, 0, $aEmptyList, $skipPathComponent);
$aAll will contain Indicated array list like:
[0] => a [1] => a/b [2] => a/b/c [3] => a/b/d
<?php
if(!defined("SEC_FILE")){define("SEC_FILE",'/framework/secure.php' );}
if (defined('LEPTON_PATH')) {
include LEPTON_PATH.SEC_FILE;
} else {
$oneback = "../";
while ((
$level < 10) && (!file_exists(
$root.SEC_FILE))) {
}
if (file_exists(
$root.SEC_FILE)) {
} else {
trigger_error(sprintf("[ <b>%s</b> ] Can't include secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
}
}
function directory_list(
string $directory,
bool $show_hidden =
false,
int $recursion_deep = 0, array &$aList = [],
string &$ignore =
"")
{
if (is_dir($directory))
{
$dir = dir( $directory );
if ($dir != NULL)
{
while (false !== ($entry = $dir->read()))
{
if ($entry[0] == '.' && $show_hidden === false)
{
continue;
}
$temp_dir = $directory."/".$entry;
if (is_dir($temp_dir))
{
$aList[] = str_replace( $ignore, "", $temp_dir );
directory_list($temp_dir, $show_hidden, $recursion_deep + 1, $aList, $ignore);
}
}
$dir->close();
}
}
if ($recursion_deep == 0)
{
natcasesort( $aList );
}
return $aList;
}
directory_list(string $directory, bool $show_hidden=false, int $recursion_deep=0, array &$aList=[], string &$ignore="")