protected static array
_items
(mixed $path, mixed $filter, mixed $recurse, mixed $full, mixed $exclude, mixed $excludeFilterString, mixed $findFiles)
/**
* Function to read the files/folders in a folder.
*
* @param string $path The path of the folder to read.
* @param string $filter A filter for file names.
* @param mixed $recurse True to recursively search into sub-folders, or an integer to specify the maximum depth.
* @param boolean $full True to return the full path to the file.
* @param array $exclude Array with names of files which should not be shown in the result.
* @param string $excludeFilterString Regexp of files to exclude
* @param boolean $findFiles True to read the files, false to read the folders
*
* @return array Files.
*
* @since 1.7.0
*/
protected static function _items($path, $filter, $recurse, $full, $exclude, $excludeFilterString, $findFiles)
{
@set_time_limit(ini_get('max_execution_time'));
$arr = array();
// Read the source directory
if (!($handle = @opendir($path))) {
return $arr;
}
while (($file = readdir($handle)) !== false) {
if ($file != '.' && $file != '..' && !\in_array($file, $exclude) && (empty($excludeFilterString) || !preg_match($excludeFilterString, $file))) {
// Compute the fullpath
$fullpath = $path . '/' . $file;
// Compute the isDir flag
$isDir = is_dir($fullpath);
if (($isDir xor $findFiles) && preg_match("/{$filter}/", $file)) {
// (fullpath is dir and folders are searched or fullpath is not dir and files are searched) and file matches the filter
if ($full) {
// Full path is requested
$arr[] = $fullpath;
} else {
// Filename is requested
$arr[] = $file;
}
}
if ($isDir && $recurse) {
// Search recursively
if (\is_int($recurse)) {
// Until depth 0 is reached
$arr = array_merge($arr, self::_items($fullpath, $filter, $recurse - 1, $full, $exclude, $excludeFilterString, $findFiles));
} else {
$arr = array_merge($arr, self::_items($fullpath, $filter, $recurse, $full, $exclude, $excludeFilterString, $findFiles));
}
}
}
}
closedir($handle);
return $arr;
}