JFolder/folders
From Joomla! Documentation
< API15:JFolder
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.
Description[edit]
Utility function to read the folders in a folder.
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax[edit]
folders($path, $filter= '.', $recurse=false, $fullpath=false, $exclude=array('.svn', 'CVS'))
Parameter Name | Default Value | Description |
---|---|---|
$path | The path of the folder to read. | |
$filter | '.' | A filter for folder names. |
$recurse | false | True to recursively search into sub-folders, or an integer to specify the maximum depth. |
$fullpath | false | True to return the full path to the folders. |
$exclude | array('.svn', 'CVS') | Array with names of folders which should not be shown in the result. |
Returns[edit]
array Folders in the given folder.
Defined in[edit]
libraries/joomla/filesystem/folder.php
Importing[edit]
jimport( 'joomla.filesystem.folder' );
Source Body[edit]
function folders($path, $filter = '.', $recurse = false, $fullpath = false, $exclude = array('.svn', 'CVS'))
{
// Initialize variables
$arr = array();
// Check to make sure the path valid and clean
$path = JPath::clean($path);
// Is the path a folder?
if (!is_dir($path)) {
JError::raiseWarning(21, 'JFolder::folder: ' . JText::_('Path is not a folder'), 'Path: ' . $path);
return false;
}
// read the source directory
$handle = opendir($path);
while (($file = readdir($handle)) !== false)
{
if (($file != '.') && ($file != '..') && (!in_array($file, $exclude))) {
$dir = $path . DS . $file;
$isDir = is_dir($dir);
if ($isDir) {
// Removes filtered directories
if (preg_match("/$filter/", $file)) {
if ($fullpath) {
$arr[] = $dir;
} else {
$arr[] = $file;
}
}
if ($recurse) {
if (is_integer($recurse)) {
$arr2 = JFolder::folders($dir, $filter, $recurse - 1, $fullpath);
} else {
$arr2 = JFolder::folders($dir, $filter, $recurse, $fullpath);
}
$arr = array_merge($arr, $arr2);
}
}
}
}
closedir($handle);
asort($arr);
return $arr;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples[edit]
Code Examples[edit]