src/Util/Filesystem.php
public static function scandir($path, $filter = 0, $order = SCANDIR_SORT_ASCENDING)
    {
        if (!$filter || (
            ($filter & self::FILE) != self::FILE &&
            ($filter & self::DIRECTORY) != self::DIRECTORY
        )) {
            $filter = self::FILE | self::DIRECTORY;
        }
        // add slash if need
        $path = self::getRealPath($path);
        // wrap path for current fs
        $wrap = Utf8::wrapPath($path);

        // scan directory
        $folders = [];
        foreach (new \DirectoryIterator($wrap) as $file) {
            /* @var $file \SplFileInfo */
            try {
                if (
                    $file->getFilename()[0] != '.' &&
                    substr($file->getFilename(), -1) != '~' &&
                    $file->getFilename() != 'pagefile.sys' && // failed read C:\pagefile.sys
                    $file->isReadable() &&
                    (
                        (($filter & self::FILE) == self::FILE && $file->isFile()) ||
                        (($filter & self::DIRECTORY) == self::DIRECTORY && $file->isDir())
                    )
                ) {
                    $folders[$file->getFilename()] = [
                        'name' => $file->getFilename(),
                        'path' => $path.$file->getFilename().DIRECTORY_SEPARATOR,
                    ];
                }
            } catch (\Exception $e) {
                // ignore all errors
            }
        }

        // order files
        if ($order == SCANDIR_SORT_ASCENDING) {
            ksort($folders);
        } elseif ($order == SCANDIR_SORT_DESCENDING) {
            ksort($folders);
            $folders = array_reverse($folders);
        }

        // add link on parent folder
        if (substr_count($path, DIRECTORY_SEPARATOR) > 1) {
            $pos = strrpos(substr($path, 0, -1), DIRECTORY_SEPARATOR) + 1;
            array_unshift($folders, [
                'name' => '..',
                'path' => substr($path, 0, $pos),
            ]);
        }

        return array_values($folders);
    }
public static function scandir($path, $filter = 0, $order = SCANDIR_SORT_ASCENDING)
    {
        if (!$filter || (
            ($filter & self::FILE) != self::FILE &&
            ($filter & self::DIRECTORY) != self::DIRECTORY
        )) {
            $filter = self::FILE | self::DIRECTORY;
        }
        // add slash if need
        $path = self::getRealPath($path);
        // wrap path for current fs
        $wrap = Utf8::wrapPath($path);

        // scan directory
        $folders = [];
        foreach (new \DirectoryIterator($wrap) as $file) {
            /* @var $file \SplFileInfo */
            try {
                if (
                    $file->getFilename()[0] != '.' &&
                    substr($file->getFilename(), -1) != '~' &&
                    $file->getFilename() != 'pagefile.sys' && // failed read C:\pagefile.sys
                    $file->isReadable() &&
                    (
                        (($filter & self::FILE) == self::FILE && $file->isFile()) ||
                        (($filter & self::DIRECTORY) == self::DIRECTORY && $file->isDir())
                    )
                ) {
                    $folders[$file->getFilename()] = [
                        'name' => $file->getFilename(),
                        'path' => $path.$file->getFilename().DIRECTORY_SEPARATOR,
                    ];
                }
            } catch (\Exception $e) {
                // ignore all errors
            }
        }

        // order files
        if ($order == SCANDIR_SORT_ASCENDING) {
            ksort($folders);
        } elseif ($order == SCANDIR_SORT_DESCENDING) {
            ksort($folders);
            $folders = array_reverse($folders);
        }

        // add link on parent folder
        if (substr_count($path, DIRECTORY_SEPARATOR) > 1) {
            $pos = strrpos(substr($path, 0, -1), DIRECTORY_SEPARATOR) + 1;
            array_unshift($folders, [
                'name' => '..',
                'path' => substr($path, 0, $pos),
            ]);
        }

        return array_values($folders);
    }
public static function scandir ( $ path , $ filter = 0 , $ order = SCANDIR_SORT_ASCENDING ) { if ( ! $ filter || ( ( $ filter & self :: FILE ) != self :: FILE && ( $ filter & self :: DIRECTORY ) != self :: DIRECTORY ) ) { $ filter = self :: FILE | self :: DIRECTORY ; } // add slash if need $ path = self :: getRealPath ( $ path ) ; // wrap path for current fs $ wrap = Utf8 :: wrapPath ( $ path ) ; // scan directory $ folders = [ ] ; foreach ( new \ DirectoryIterator ( $ wrap ) as $ file ) { /* @var $file \SplFileInfo */ try { if ( $ file -> getFilename ( ) [ 0 ] != '.' && substr ( $ file -> getFilename ( ) , - 1 ) != '~' && $ file -> getFilename ( ) != 'pagefile.sys' && // failed read C:\pagefile.sys $ file -> isReadable ( ) && ( ( ( $ filter & self :: FILE ) == self :: FILE && $ file -> isFile ( ) ) || ( ( $ filter & self :: DIRECTORY ) == self :: DIRECTORY && $ file -> isDir ( ) ) ) ) { $ folders [ $ file -> getFilename ( ) ] = [ 'name' => $ file -> getFilename ( ) , 'path' => $ path . $ file -> getFilename ( ) . DIRECTORY_SEPARATOR , ] ; } } catch ( \ Exception $ e ) { // ignore all errors } } // order files if ( $ order == SCANDIR_SORT_ASCENDING ) { ksort ( $ folders ) ; } elseif ( $ order == SCANDIR_SORT_DESCENDING ) { ksort ( $ folders ) ; $ folders = array_reverse ( $ folders ) ; } // add link on parent folder if ( substr_count ( $ path , DIRECTORY_SEPARATOR ) > 1 ) { $ pos = strrpos ( substr ( $ path , 0 , - 1 ) , DIRECTORY_SEPARATOR ) + 1 ; array_unshift ( $ folders , [ 'name' => '..' , 'path' => substr ( $ path , 0 , $ pos ) , ] ) ; } return array_values ( $ folders ) ; }
List files and directories inside the specified path.

@param string $path
@param int $filter
@param int $order

@return array
List files and directories inside the specified path .