src/Koldy/Filesystem/Directory.php
public static function read(string $path, string $filter = null): array
    {
        if (is_dir($path) && $handle = opendir($path)) {
            $files = [];

            if (substr($path, -1) != '/') {
                $path .= '/';
            }

            while (false !== ($entry = readdir($handle))) {
                if ($entry !== '.' && $entry !== '..') {
                    if ($filter === null || preg_match($filter, $entry)) {
                        $fullPath = $path . $entry;

                        if (substr($fullPath, 0, 1) == '.') {
                            $fullPath = stream_resolve_include_path($path . $entry);
                        }

                        $files[$fullPath] = $entry;
                    }
                }
            }

            return $files;
        } else {
            throw new FilesystemException("Unable to open directory on path={$path}");
        }
    }
public static function read(string $path, string $filter = null): array
    {
        if (is_dir($path) && $handle = opendir($path)) {
            $files = [];

            if (substr($path, -1) != '/') {
                $path .= '/';
            }

            while (false !== ($entry = readdir($handle))) {
                if ($entry !== '.' && $entry !== '..') {
                    if ($filter === null || preg_match($filter, $entry)) {
                        $fullPath = $path . $entry;

                        if (substr($fullPath, 0, 1) == '.') {
                            $fullPath = stream_resolve_include_path($path . $entry);
                        }

                        $files[$fullPath] = $entry;
                    }
                }
            }

            return $files;
        } else {
            throw new FilesystemException("Unable to open directory on path={$path}");
        }
    }
public static function read ( string $ path , string $ filter = null ) : array { if ( is_dir ( $ path ) && $ handle = opendir ( $ path ) ) { $ files = [ ] ; if ( substr ( $ path , - 1 ) != '/' ) { $ path .= '/' ; } while ( false !== ( $ entry = readdir ( $ handle ) ) ) { if ( $ entry !== '.' && $ entry !== '..' ) { if ( $ filter === null || preg_match ( $ filter , $ entry ) ) { $ fullPath = $ path . $ entry ; if ( substr ( $ fullPath , 0 , 1 ) == '.' ) { $ fullPath = stream_resolve_include_path ( $ path . $ entry ) ; } $ files [ $ fullPath ] = $ entry ; } } } return $ files ; } else { throw new FilesystemException ( "Unable to open directory on path={$path}" ) ; } }
Get the list of all files and folders from the given folder

@param string $path the directory path to read
@param string $filter [optional] regex for filtering the list

@return array assoc; the key is full path of the file and value is only file name
@throws FilesystemException
@example return array('/var/www/site.tld/folder/croatia.png' => 'croatia.png')
Get the list of all files and folders from the given folder