public static function getFilenames($pathname, $extension = null) {

        // Check if the directory exists.
        if (false === file_exists($pathname)) {
            throw new FileNotFoundException($pathname);
        }

        // Initialize the filenames.
        $filenames = [];

        // Open the directory.
        if (false !== ($directory = opendir($pathname))) {

            // Initialize the offset.
            $offset = strlen($extension);

            // Read the directory.
            while (($file = readdir($directory)) !== false) {

                // Determines if the file should be added.
                if (false === in_array($file, [".", ".."]) && ((null === $extension) || 0 === substr_compare($file, $extension, -$offset))) {
                    $filenames[] = $file;
                }
            }

            // Close the directory.
            closedir($directory);
        }

        // Return the filenames.
        return $filenames;
    }
public static function getFilenames($pathname, $extension = null) {

        // Check if the directory exists.
        if (false === file_exists($pathname)) {
            throw new FileNotFoundException($pathname);
        }

        // Initialize the filenames.
        $filenames = [];

        // Open the directory.
        if (false !== ($directory = opendir($pathname))) {

            // Initialize the offset.
            $offset = strlen($extension);

            // Read the directory.
            while (($file = readdir($directory)) !== false) {

                // Determines if the file should be added.
                if (false === in_array($file, [".", ".."]) && ((null === $extension) || 0 === substr_compare($file, $extension, -$offset))) {
                    $filenames[] = $file;
                }
            }

            // Close the directory.
            closedir($directory);
        }

        // Return the filenames.
        return $filenames;
    }
public static function getFilenames ( $ pathname , $ extension = null ) { // Check if the directory exists. if ( false === file_exists ( $ pathname ) ) { throw new FileNotFoundException ( $ pathname ) ; } // Initialize the filenames. $ filenames = [ ] ; // Open the directory. if ( false !== ( $ directory = opendir ( $ pathname ) ) ) { // Initialize the offset. $ offset = strlen ( $ extension ) ; // Read the directory. while ( ( $ file = readdir ( $ directory ) ) !== false ) { // Determines if the file should be added. if ( false === in_array ( $ file , [ "." , ".." ] ) && ( ( null === $ extension ) || 0 === substr_compare ( $ file , $ extension , - $ offset ) ) ) { $ filenames [ ] = $ file ; } } // Close the directory. closedir ( $ directory ) ; } // Return the filenames. return $ filenames ; }
Get the filenames.

@param string $pathname The pathname.
@param string $extension The file extension.
@return array Returns the filenames.
@throws FileNotFoundException Throws a file not found exception if the directory does not exists.
Get the filenames .