public function getDirectoryFiles($dirPath, $ignore = null)
    {
        $files = [];
        $pattern = '/^\..+'; // Ignore all dot files by default
        $splitCamelCase = '/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/';
        $ignoreDirectories = false;

        if (is_string($ignore) && !empty($ignore)) {
            // If 'dir' or 'directory' strings are set, then set flag to ignore directories
            if ($ignore === 'dir' || $ignore === 'directory') {
                $ignoreDirectories = true;
            } else {
                // Add it to the regex
                $pattern .= '|' . $ignore;
            }
        } elseif (is_array($ignore)) {
            // If 'dir' or 'directory' strings are set, then set flag to ignore directories
            if (in_array('dir', $ignore) || in_array('directory', $ignore)) {
                $ignoreDirectories = true;
                $ignore = array_diff($ignore, ['dir', 'directory']);
            }

            // Add it to the regex
            $multiIgnores = implode('|', $ignore);
            $pattern .= empty($multiIgnores) ? '' : '|' . $multiIgnores;
        }

        $pattern .= '/'; // Close regex

        if (is_dir($dirPath)) {
            foreach (new FilesystemIterator($dirPath) as $dirObject) {
                if (($ignoreDirectories && $dirObject->isDir()) || preg_match($pattern, $dirObject->getFilename())) {
                    continue;
                }

                $baseName = $dirObject->getBasename('.' . $dirObject->getExtension());
                $readableFileName = preg_replace($splitCamelCase, '$1 ', $baseName);
                $readableFileName = ucwords($readableFileName);

                $files[] = [
                    'filename' => $dirObject->getFilename(),
                    'basename' => $baseName,
                    'readname' => $readableFileName
                ];
            }
        }

        return $files;
    }
public function getDirectoryFiles($dirPath, $ignore = null)
    {
        $files = [];
        $pattern = '/^\..+'; // Ignore all dot files by default
        $splitCamelCase = '/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/';
        $ignoreDirectories = false;

        if (is_string($ignore) && !empty($ignore)) {
            // If 'dir' or 'directory' strings are set, then set flag to ignore directories
            if ($ignore === 'dir' || $ignore === 'directory') {
                $ignoreDirectories = true;
            } else {
                // Add it to the regex
                $pattern .= '|' . $ignore;
            }
        } elseif (is_array($ignore)) {
            // If 'dir' or 'directory' strings are set, then set flag to ignore directories
            if (in_array('dir', $ignore) || in_array('directory', $ignore)) {
                $ignoreDirectories = true;
                $ignore = array_diff($ignore, ['dir', 'directory']);
            }

            // Add it to the regex
            $multiIgnores = implode('|', $ignore);
            $pattern .= empty($multiIgnores) ? '' : '|' . $multiIgnores;
        }

        $pattern .= '/'; // Close regex

        if (is_dir($dirPath)) {
            foreach (new FilesystemIterator($dirPath) as $dirObject) {
                if (($ignoreDirectories && $dirObject->isDir()) || preg_match($pattern, $dirObject->getFilename())) {
                    continue;
                }

                $baseName = $dirObject->getBasename('.' . $dirObject->getExtension());
                $readableFileName = preg_replace($splitCamelCase, '$1 ', $baseName);
                $readableFileName = ucwords($readableFileName);

                $files[] = [
                    'filename' => $dirObject->getFilename(),
                    'basename' => $baseName,
                    'readname' => $readableFileName
                ];
            }
        }

        return $files;
    }
public function getDirectoryFiles ( $ dirPath , $ ignore = null ) { $ files = [ ] ; $ pattern = '/^\..+' ; // Ignore all dot files by default $ splitCamelCase = '/(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])/' ; $ ignoreDirectories = false ; if ( is_string ( $ ignore ) && ! empty ( $ ignore ) ) { // If 'dir' or 'directory' strings are set, then set flag to ignore directories if ( $ ignore === 'dir' || $ ignore === 'directory' ) { $ ignoreDirectories = true ; } else { // Add it to the regex $ pattern .= '|' . $ ignore ; } } elseif ( is_array ( $ ignore ) ) { // If 'dir' or 'directory' strings are set, then set flag to ignore directories if ( in_array ( 'dir' , $ ignore ) || in_array ( 'directory' , $ ignore ) ) { $ ignoreDirectories = true ; $ ignore = array_diff ( $ ignore , [ 'dir' , 'directory' ] ) ; } // Add it to the regex $ multiIgnores = implode ( '|' , $ ignore ) ; $ pattern .= empty ( $ multiIgnores ) ? '' : '|' . $ multiIgnores ; } $ pattern .= '/' ; // Close regex if ( is_dir ( $ dirPath ) ) { foreach ( new FilesystemIterator ( $ dirPath ) as $ dirObject ) { if ( ( $ ignoreDirectories && $ dirObject -> isDir ( ) ) || preg_match ( $ pattern , $ dirObject -> getFilename ( ) ) ) { continue ; } $ baseName = $ dirObject -> getBasename ( '.' . $ dirObject -> getExtension ( ) ) ; $ readableFileName = preg_replace ( $ splitCamelCase , '$1 ' , $ baseName ) ; $ readableFileName = ucwords ( $ readableFileName ) ; $ files [ ] = [ 'filename' => $ dirObject -> getFilename ( ) , 'basename' => $ baseName , 'readname' => $ readableFileName ] ; } } return $ files ; }
Get Directory Files

Scans a given directory, and returns a multi-dimension array of file names
Ignores '.' '..' and sub directories by default
$ignore accepts file names or regex patterns to ignore
@param  string $dirPath Path to directory to scan
@param  mixed  $ignore  String | Array
@return array
Get Directory Files