Actions

API15

JFolder/listFolderTree

From Joomla! Documentation

< API15:JFolder
Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Lists folder in format suitable for tree display.

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax

listFolderTree($path, $filter, $maxLevel=3, $level=0, $parent=0)
Parameter Name Default Value Description
$path The path of the folder to read.
$filter A filter for folder names.
$maxLevel 3 The maximum number of levels to recursively read, defaults to three.
$level 0 The current level, optional.
$parent 0 Unique identifier of the parent folder, if any.

Returns

array Folders in the given folder.

Defined in

libraries/joomla/filesystem/folder.php

Importing

jimport( 'joomla.filesystem.folder' );

Source Body

function listFolderTree($path, $filter, $maxLevel = 3, $level = 0, $parent = 0)
{
        $dirs = array ();
        if ($level == 0) {
                $GLOBALS['_JFolder_folder_tree_index'] = 0;
        }
        if ($level < $maxLevel) {
                $folders = JFolder::folders($path, $filter);
                // first path, index foldernames
                foreach ($folders as $name) {
                        $id = ++$GLOBALS['_JFolder_folder_tree_index'];
                        $fullName = JPath::clean($path . DS . $name);
                        $dirs[] = array(
                                'id' => $id,
                                'parent' => $parent,
                                'name' => $name,
                                'fullname' => $fullName,
                                'relname' => str_replace(JPATH_ROOT, '', $fullName)
                        );
                        $dirs2 = JFolder::listFolderTree($fullName, $filter, $maxLevel, $level + 1, $id);
                        $dirs = array_merge($dirs, $dirs2);
                }
        }
        return $dirs;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />