Difference between revisions of "JFolder/files"
From Joomla! Documentation
< API16:JFolder
(New page: ===Description===
Utility function to read the files in a folder.
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>Edit Descripton<now...) |
m (removing red link to edit, no existant pages) |
||
Line 3: | Line 3: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Syntax=== | ===Syntax=== | ||
Line 107: | Line 107: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
− | <nowiki>[< | + | <nowiki>[<! removed edit link to red link >]</nowiki> |
</span> | </span> | ||
− | + | <! removed transcluded page call, red link never existed > | |
===Examples=== | ===Examples=== | ||
Line 122: | Line 122: | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
+ | [[Category:Archived pages API16]] |
Revision as of 21:52, 13 May 2013
The "API16" 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 files in a folder.
[<! removed edit link to red link >]
<! removed transcluded page call, red link never existed >
Syntax[edit]
static files($path, $filter= '.', $recurse=false, $fullpath=false, $exclude=array('.svn', 'CVS','.DS_Store','__MACOSX'), $excludefilter=array('^\..*','.*~'))
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','.DS_Store','__MACOSX') | Array with names of files which should not be shown in the result. |
$excludefilter | array('^\..*','.*~') |
Returns[edit]
array Files in the given folder.
Defined in[edit]
libraries/joomla/filesystem/folder.php
Importing[edit]
jimport( 'joomla.filesystem.folder' );
Source Body[edit]
public static function files($path, $filter = '.', $recurse = false, $fullpath = false, $exclude = array('.svn', 'CVS','.DS_Store','__MACOSX'), $excludefilter = array('^\..*','.*~'))
{
// Initialise 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);
if(count($excludefilter)) {
$excludefilter = '/('. implode('|', $excludefilter) .')/';
} else {
$excludefilter = '';
}
while (($file = readdir($handle)) !== false)
{
if (($file != '.') && ($file != '..') && (!in_array($file, $exclude)) && (!$excludefilter || !preg_match($excludefilter, $file))) {
$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[edit]
<CodeExamplesForm />