public function files($directory, $recursive = false)
    {
        $result     = [];
        $recursive  = boolval($recursive);

        if ( ! $this->isDirectory($directory)) return [];

        $items = new FilesystemIterator($directory);

        foreach ($items as $item) {
            if ($item->isFile()) {
                $result[]       = $item->getPathname();
            } elseif ($recursive && $item->isDir() && ! $item->isLink()) {
                $subFiles       = $this->files($item->getPathname(), $recursive);
                foreach ($subFiles as $file) {
                    $result[]   = $file;
                }
            }
        }

        return $result;
    }
public function files($directory, $recursive = false)
    {
        $result     = [];
        $recursive  = boolval($recursive);

        if ( ! $this->isDirectory($directory)) return [];

        $items = new FilesystemIterator($directory);

        foreach ($items as $item) {
            if ($item->isFile()) {
                $result[]       = $item->getPathname();
            } elseif ($recursive && $item->isDir() && ! $item->isLink()) {
                $subFiles       = $this->files($item->getPathname(), $recursive);
                foreach ($subFiles as $file) {
                    $result[]   = $file;
                }
            }
        }

        return $result;
    }
public function files ( $ directory , $ recursive = false ) { $ result = [ ] ; $ recursive = boolval ( $ recursive ) ; if ( ! $ this -> isDirectory ( $ directory ) ) return [ ] ; $ items = new FilesystemIterator ( $ directory ) ; foreach ( $ items as $ item ) { if ( $ item -> isFile ( ) ) { $ result [ ] = $ item -> getPathname ( ) ; } elseif ( $ recursive && $ item -> isDir ( ) && ! $ item -> isLink ( ) ) { $ subFiles = $ this -> files ( $ item -> getPathname ( ) , $ recursive ) ; foreach ( $ subFiles as $ file ) { $ result [ ] = $ file ; } } } return $ result ; }
get all files in directory

@param string $directory
@param bool $recursive
@return array
get all files in directory