lib/Pico.php
public function getFiles($directory, $fileExtension = '', $order = self::SORT_ASC)
    {
        $directory = rtrim($directory, '/');
        $result = array();

        // scandir() reads files in alphabetical order
        $files = scandir($directory, $order);
        $fileExtensionLength = strlen($fileExtension);
        if ($files !== false) {
            foreach ($files as $file) {
                // exclude hidden files/dirs starting with a .; this also excludes the special dirs . and ..
                // exclude files ending with a ~ (vim/nano backup) or # (emacs backup)
                if (($file[0] === '.') || in_array(substr($file, -1), array('~', '#'), true)) {
                    continue;
                }

                if (is_dir($directory . '/' . $file)) {
                    // get files recursively
                    $result = array_merge($result, $this->getFiles($directory . '/' . $file, $fileExtension, $order));
                } elseif (!$fileExtension || (substr($file, -$fileExtensionLength) === $fileExtension)) {
                    $result[] = $directory . '/' . $file;
                }
            }
        }

        return $result;
    }
public function getFiles($directory, $fileExtension = '', $order = self::SORT_ASC)
    {
        $directory = rtrim($directory, '/');
        $result = array();

        // scandir() reads files in alphabetical order
        $files = scandir($directory, $order);
        $fileExtensionLength = strlen($fileExtension);
        if ($files !== false) {
            foreach ($files as $file) {
                // exclude hidden files/dirs starting with a .; this also excludes the special dirs . and ..
                // exclude files ending with a ~ (vim/nano backup) or # (emacs backup)
                if (($file[0] === '.') || in_array(substr($file, -1), array('~', '#'), true)) {
                    continue;
                }

                if (is_dir($directory . '/' . $file)) {
                    // get files recursively
                    $result = array_merge($result, $this->getFiles($directory . '/' . $file, $fileExtension, $order));
                } elseif (!$fileExtension || (substr($file, -$fileExtensionLength) === $fileExtension)) {
                    $result[] = $directory . '/' . $file;
                }
            }
        }

        return $result;
    }
public function getFiles ( $ directory , $ fileExtension = '' , $ order = self :: SORT_ASC ) { $ directory = rtrim ( $ directory , '/' ) ; $ result = array ( ) ; // scandir() reads files in alphabetical order $ files = scandir ( $ directory , $ order ) ; $ fileExtensionLength = strlen ( $ fileExtension ) ; if ( $ files !== false ) { foreach ( $ files as $ file ) { // exclude hidden files/dirs starting with a .; this also excludes the special dirs . and .. // exclude files ending with a ~ (vim/nano backup) or # (emacs backup) if ( ( $ file [ 0 ] === '.' ) || in_array ( substr ( $ file , - 1 ) , array ( '~' , '#' ) , true ) ) { continue ; } if ( is_dir ( $ directory . '/' . $ file ) ) { // get files recursively $ result = array_merge ( $ result , $ this -> getFiles ( $ directory . '/' . $ file , $ fileExtension , $ order ) ) ; } elseif ( ! $ fileExtension || ( substr ( $ file , - $ fileExtensionLength ) === $ fileExtension ) ) { $ result [ ] = $ directory . '/' . $ file ; } } } return $ result ; }
Recursively walks through a directory and returns all containing files
matching the specified file extension

@param string $directory     start directory
@param string $fileExtension return files with the given file extension
only (optional)
@param int    $order         specify whether and how files should be
sorted; use Pico::SORT_ASC for a alphabetical ascending order (this
is the default behaviour), Pico::SORT_DESC for a descending order
or Pico::SORT_NONE to leave the result unsorted

@return array list of found files
Recursively walks through a directory and returns all containing files matching the specified file extension