Returns summary info for specified folder
@param string $dir
@param array $result
@return array
550893
public function getDirSummary($dir, &$result = ['size' => 0, 'files' => 0, 'folders' => 0]) {
        // suppress permission denied and other errors
        $files = @scandir($dir);
        if ($files === false) {
            return $result;
        }

        foreach ($files as $file) {
            if ($file == "." || $file == "..") {
                continue;
            }
            $path = $dir . $file;
            $is_dir = is_dir($path);

            if ($is_dir && $this->is_allowed_name($file, true)) {
                $result['folders'] ++;
                $this->getDirSummary($path . '/', $result);
            }
            if (!$is_dir && $this->is_allowed_name($file, false)) {
                $result['files'] ++;
                $result['size'] += filesize($path);
            }
        }

        return $result;
    }
621268
public static function getFirstLevelDirs($dir)
    {
        $iterator = new DirectoryIterator($dir);
        $result = array();

        foreach ($iterator as $item) {
            if (!$item->isDot() && $item->isDir()) {
                array_push($result, $item->getFileName());
            }
        }

        return $result;
    }
280087
protected function _rmdir( $dir )
    {
        $iterator = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator( $dir,
                RecursiveDirectoryIterator::CURRENT_AS_FILEINFO |
                RecursiveDirectoryIterator::SKIP_DOTS
            ),
            RecursiveIteratorIterator::CHILD_FIRST
        );

        $result = true;

        foreach ( $iterator as $info )
        {
            $path = $info->getPathname();

            switch ( true )
            {
                case $info->isFile():
                case $info->isLink():
                    $result = $result && @ unlink( $path );
                    break;

                case $info->isDir():
                    $result = $result && @ rmdir( $path );
                    break;
            }

        }

        return $result && @ rmdir( $dir );
    }
683767
private function getFolderContent($objLayer, $folderInfo, $key, $count)
    {
        $month = array('01' => 'Januar', '02', 'Frebruar', '03' => 'März', '04' => 'April', '05' => 'Mai', '06' => 'Juni', '07' => 'Juli', '08' => 'August', '09' => 'Sebtember', '10' => 'Oktober', '11' => 'November', '12' => 'Dezember');
        
        
        $folder = array(
            "id"           => strval($objLayer->id.$count),
            "pid"          => $key,
            "name"         => utf8_encode($folderInfo['filename']),
            "hide"         => $objLayer->published,
            "display"      => true,
            "type"         => $objLayer->location_type,
            "hasChilds"    => true,
            "childsCount"  => '',
            "childs"       => array()
        );
        return $folder;
    }
643428
public function saveCSV ($dir, array $result)
	{
		// make sure the directory exists
		$dirname = $this->reportDir.DIRECTORY_SEPARATOR.$dir;

		if ($dirname && !is_dir($dirname)) {
			mkdir ($dirname, 0777, true);
		}

		$content  = '"total","testable","untestable"'."\n";
		$content .= '"'.$result['total'].'","'.$result['testable'].'","'.($result['total']-$result['testable']).'"'."\n";
		
		// save
		file_put_contents ($dirname.DIRECTORY_SEPARATOR.'totals.csv', $content);
	}
599615
public function parse(array $dirs, $cacheDir = null)
    {
        $results = $this->parseFiles($dirs, '/\.php$/', $cacheDir);
        $classes = [];

        foreach ($results as $refs) {
            foreach ($refs as $className => $ref) {
                $classes[$className] = $ref;
            }
        }

        return $classes;
    }
1227595
protected function scanDir($dir)
    {
        $fileinfos = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir));
        $files     = [];
        foreach ($fileinfos as $pathname => $fileinfo) {
            if (!$fileinfo->isFile()) {
                continue;
            }

            $files[] = $pathname;
        }

        return $this->scanArray($files);
    }
747921
static function recursiveFind( $dir, $suffix )
    {
        $returnFiles = array();
        if ( $handle = @opendir( $dir ) )
        {
            while ( ( $file = readdir( $handle ) ) !== false )
            {
                if ( ( $file == "." ) || ( $file == ".." ) )
                {
                    continue;
                }
                if ( is_dir( $dir . '/' . $file ) )
                {
                    if ( $file[0] != "." )
                    {
                        $files = eZDir::recursiveFind( $dir . '/' . $file, $suffix );
                        $returnFiles = array_merge( $files, $returnFiles );
                    }
                }
                else
                {
                    if ( preg_match( "/$suffix$/", $file ) )
                        $returnFiles[] = $dir . '/' . $file;
                }
            }
            @closedir( $handle );
        }
        return $returnFiles;
    }
1249478
public function getDirs($dir)
    {
        $dirArr = array();
        $files = ftp_rawlist($this->link, $dir);
        foreach ($files as $v) {
            $file = ltrim(strrchr($v, ' '), ' ');
            $path = "{$dir}/{$file}";
            if (preg_match('/^d/', $v)) {
                if (in_array($file, array('.', '..'))) {
                    continue;
                }
                if (preg_match('/^[a-zA-z0-9]+$/', $file)) { //file check
                    $dirArr[] = $path;
                    $dirArr = array_merge($dirArr, self::getDirs($path));
                }
            }
        }
        return $dirArr;
    }
373477
public function listDirectory($directory, $recursive = false)
    {
        $results = $this->scanDirectory($directory, $recursive);

        if (false === $results) {
            throw new \RuntimeException(sprintf(
                'Unable to list directory "%s", maybe it is not a directory '.
                'or it does not exist.',
                $directory
            ));
        }

        return array(
            'files'       => $results[0],
            'directories' => $results[1]
        );
    }
644240
public function loadJsonFiles($dir)
    {
        return coollect(glob("$dir/*.json*"))->mapWithKeys(function ($file) {
            $key = str_replace('.json', '', str_replace('.json5', '', basename($file)));

            return [$key => $this->loadJson($file)];
        });
    }
477758
private function getSectionInfo($dir, $file)
    {
        $info = null;

        try {
            $data = Yaml::parse(file_get_contents($dir.$file));

            if (array_key_exists('kunstmaan_page_part', $data)) {
                //Get rid of the bundle config lines
                $data = array_values(array_values(array_values($data)[0])[0])[0];
            }

            $info = [
                'name' => $data['name'],
                'context' => $data['context'],
                'file' => $file,
                //'file_clean' => substr($file, 0, strlen($file)-4)
            ];
        } catch (ParseException $e) {
        }

        return $info;
    }
620932
protected function append_result($result)
    {
        $this->meta['count'] += $result->count();

        // append UIDs to global index
        $folder = $result->get_parameters('MAILBOX');
        $index  = array_map(function($uid) use ($folder) { return $uid . '-' . $folder; }, $result->get());

        $this->index = array_merge($this->index, $index);
    }
435221
public function files($dir)
    {
        $dir = $this->alias->resolve($dir);

        $files = [];
        foreach ($this->glob($dir . (strpos($dir, '*') === false ? '/*' : ''), SCANDIR_SORT_ASCENDING) as $item) {
            if (is_file($item)) {
                $files[] = $item;
            }
        }

        return $files;
    }
507333
public function listDirectory($directory = '.', $ref = 'HEAD')
    {
        $directory  = FileSystem::normalizeDirectorySeparator($directory);
        $directory  = $this->resolveLocalPath(rtrim($directory, '/') . '/');
        $path       = $this->getRepositoryPath();

        /** @var $result CallResult */
        $result = $this->getGit()->{'ls-tree'}($path, array(
            '--name-only',
            '--full-name',
            '-z',
            $ref,
            $this->translatePathspec($directory)
        ));
        $result->assertSuccess(sprintf('Cannot list directory "%s" at "%s" from "%s"',
            $directory, $ref, $this->getRepositoryPath()
        ));

        $output     = $result->getStdOut();
        $listing    = array_map(function($f) use ($directory) {
            return str_replace($directory, '', trim($f));
        }, explode("\x0", $output));
        return $listing;
    }
17999
static public function getFolders( $dir, $recursive = false )
    {
        $subDirs = [];
        if ( ( $dh = opendir( $dir ) ) ) {
            while ( ( $file = readdir( $dh ) ) !== false ) {
                if ( $file !== '.' && $file !== '..' && is_dir( $dir . '/' . $file ) ) {
                    $subDirs[] = $file;
                    if ( $recursive ) {
                        $subDirs = array_merge( $subDirs, self::getFolders( $dir . DS . $file, true ) );
                    }
                }
            }
            closedir( $dh );
        }
        return $subDirs;
    }
146684
public static function getFolder($dir, $exclude = [ '.', '..' ])
    {
        $folder = [];
        if (($dh     = opendir($dir))) {
            while (($file = readdir($dh)) !== false) {
                if (!in_array($file, $exclude) && self::getFileExtension($file) === '') {
                    $folder[] = $file;
                }
            }
            closedir($dh);
        }

        return $folder;
    }