Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. System.php

function System::_dirToStruct

Creates a nested array representing the structure of a directory

System::_dirToStruct('dir1', 0) => Array ( [dirs] => Array ( [0] => dir1 )

[files] => Array ( [0] => dir1/file2 [1] => dir1/file3 ) )

Parameters

string $sPath Name of the directory:

integer $maxinst max. deep of the lookup:

integer $aktinst starting deep of the lookup:

bool $silent if true, do not emit errors.:

Return value

array the structure of the dir

2 calls to System::_dirToStruct()
System::find in vendor/pear/pear-core-minimal/src/System.php
The "find" command
System::_multipleToStruct in vendor/pear/pear-core-minimal/src/System.php
Creates a nested array representing the structure of a directory and files

File

vendor/pear/pear-core-minimal/src/System.php, line 141

Class

System
System offers cross platform compatible system functions

Code

protected static function _dirToStruct($sPath, $maxinst, $aktinst = 0, $silent = false) {
    $struct = array(
        'dirs' => array(),
        'files' => array(),
    );
    if (($dir = @opendir($sPath)) === false) {
        if (!$silent) {
            System::raiseError("Could not open dir {$sPath}");
        }
        return $struct;
        // XXX could not open error
    }
    $struct['dirs'][] = $sPath = realpath($sPath);
    // XXX don't add if '.' or '..' ?
    $list = array();
    while (false !== ($file = readdir($dir))) {
        if ($file != '.' && $file != '..') {
            $list[] = $file;
        }
    }
    closedir($dir);
    natsort($list);
    if ($aktinst < $maxinst || $maxinst == 0) {
        foreach ($list as $val) {
            $path = $sPath . DIRECTORY_SEPARATOR . $val;
            if (is_dir($path) && !is_link($path)) {
                $tmp = System::_dirToStruct($path, $maxinst, $aktinst + 1, $silent);
                $struct = array_merge_recursive($struct, $tmp);
            }
            else {
                $struct['files'][] = $path;
            }
        }
    }
    return $struct;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal