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;
    }
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;
    }
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 ; }
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
)
)
@param    string  $sPath      Name of the directory
@param    integer $maxinst    max. deep of the lookup
@param    integer $aktinst    starting deep of the lookup
@param    bool    $silent     if true, do not emit errors.
@return   array   the structure of the dir
@static
@access   private
Creates a nested array representing the structure of a directory