public function scandir(string $dir, array $options = [])
    {
        $options = array_replace(
            [
                'sort'          => SCANDIR_SORT_NONE,
                'context'       => null,
                'recursive'     => false,
                'skipDots'      => true,
                'skipSymlinks'  => false
            ],
            $options
        );

        if (!$options['skipSymlinks'] && is_link($dir)) {
            $dir = @readlink($dir);
        }

        $args = [
            $dir,
            $options['sort']
        ];

        if ($options['context']) {
            $args[] = $options['context'];
        }

        if (($tmp = @scandir(...$args)) === false) {
            throw IOException::create(
                'Couldn\'t scan directory "'.$dir.'". Last PHP Error: '.
                print_r($this->getLastPhpError(), true)
            );
        }

        if ($options['skipDots']) {
            $tmp = array_diff($tmp, array('.', '..'));
        }

        $result = [];

        foreach ($tmp as $f) {
            $f = $dir.'/'.$f;

            if ($options['skipSymlinks'] && is_link($f)) {
                continue;
            }

            $result[] = $f;

            if ($options['recursive'] && is_dir($f)) {
                $result = array_merge(
                    $result,
                    $this->scandir($f, $options)
                );
            }
        }

        $tmp = null;

        return array_unique($result);
    }
public function scandir(string $dir, array $options = [])
    {
        $options = array_replace(
            [
                'sort'          => SCANDIR_SORT_NONE,
                'context'       => null,
                'recursive'     => false,
                'skipDots'      => true,
                'skipSymlinks'  => false
            ],
            $options
        );

        if (!$options['skipSymlinks'] && is_link($dir)) {
            $dir = @readlink($dir);
        }

        $args = [
            $dir,
            $options['sort']
        ];

        if ($options['context']) {
            $args[] = $options['context'];
        }

        if (($tmp = @scandir(...$args)) === false) {
            throw IOException::create(
                'Couldn\'t scan directory "'.$dir.'". Last PHP Error: '.
                print_r($this->getLastPhpError(), true)
            );
        }

        if ($options['skipDots']) {
            $tmp = array_diff($tmp, array('.', '..'));
        }

        $result = [];

        foreach ($tmp as $f) {
            $f = $dir.'/'.$f;

            if ($options['skipSymlinks'] && is_link($f)) {
                continue;
            }

            $result[] = $f;

            if ($options['recursive'] && is_dir($f)) {
                $result = array_merge(
                    $result,
                    $this->scandir($f, $options)
                );
            }
        }

        $tmp = null;

        return array_unique($result);
    }
public function scandir ( string $ dir , array $ options = [ ] ) { $ options = array_replace ( [ 'sort' => SCANDIR_SORT_NONE , 'context' => null , 'recursive' => false , 'skipDots' => true , 'skipSymlinks' => false ] , $ options ) ; if ( ! $ options [ 'skipSymlinks' ] && is_link ( $ dir ) ) { $ dir = @ readlink ( $ dir ) ; } $ args = [ $ dir , $ options [ 'sort' ] ] ; if ( $ options [ 'context' ] ) { $ args [ ] = $ options [ 'context' ] ; } if ( ( $ tmp = @ scandir ( ... $ args ) ) === false ) { throw IOException :: create ( 'Couldn\'t scan directory "' . $ dir . '". Last PHP Error: ' . print_r ( $ this -> getLastPhpError ( ) , true ) ) ; } if ( $ options [ 'skipDots' ] ) { $ tmp = array_diff ( $ tmp , array ( '.' , '..' ) ) ; } $ result = [ ] ; foreach ( $ tmp as $ f ) { $ f = $ dir . '/' . $ f ; if ( $ options [ 'skipSymlinks' ] && is_link ( $ f ) ) { continue ; } $ result [ ] = $ f ; if ( $ options [ 'recursive' ] && is_dir ( $ f ) ) { $ result = array_merge ( $ result , $ this -> scandir ( $ f , $ options ) ) ; } } $ tmp = null ; return array_unique ( $ result ) ; }
Scans a directory and returns an array of files, symlinks and directories.

Options:

- sort:              One of the SCANDIR_SORT_* constants. Defaults to SCANDIR_SORT_NONE.
- context:           Context to use for the scandir function. Defaults to "null".
- recursive:         If this option is "true", we'll call this method for every directory
found. Defaults to "false".
- skipDots:          If "true", then "." and ".." won't be returned. Defaults to "true".
- skipSymlinks:      If "true", then symlinks will be skipped. Defaults to "true". Please note
that this option also applies if the $dir argument is a symlink. If this
option is false then we will call "readlink" to determine where the symlink
points to.

@param string $dir     - Directory to scan.
@param array  $options - Options.

@throws IOException

@return array
Scans a directory and returns an array of files symlinks and directories .