API15:JFolder/files
From Joomla! Documentation
Description
Utility function to read the files in a folder.
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax
files($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 file 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 file. |
| $exclude | array('.svn', 'CVS') | Array with names of files which should not be shown in the result. |
Returns
array Files in the given folder.
Defined in
libraries/joomla/filesystem/folder.php
Importing
jimport( 'joomla.filesystem.folder' );
Source Body
function files($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::files: ' . 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) {
if ($recurse) {
if (is_integer($recurse)) {
$arr2 = JFolder::files($dir, $filter, $recurse - 1, $fullpath);
} else {
$arr2 = JFolder::files($dir, $filter, $recurse, $fullpath);
}
$arr = array_merge($arr, $arr2);
}
} else {
if (preg_match("/$filter/", $file)) {
if ($fullpath) {
$arr[] = $path . DS . $file;
} else {
$arr[] = $file;
}
}
}
}
}
closedir($handle);
asort($arr);
return $arr;
}
[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >
Examples
Code Examples