public static function listFilesInFolder($strPath, $blnSkipFolders = true, $strFilenamePattern = null)
    {
        // strip off the trailing slash if it's there
        if ($strPath[strlen($strPath) - 1] == "/") {
            $strPath = substr($strPath, 0, -1);
        }

        $result = array();

        $originalSet = self::getFilesInFolderHelper($strPath);
        if (!$originalSet) {
            return $result;
        }    // empty directory, or directory does not exist

        foreach ($originalSet as $item) {
            $childPath = $strPath . "/" . $item;
            if (is_dir($childPath)) {
                $childItems = self::listFilesInFolder($childPath);
                foreach ($childItems as $child) {
                    $result[] = $item . "/" . $child;
                }
            }

            if (!$blnSkipFolders || !is_dir($childPath)) {
                if (!$strFilenamePattern || ($strFilenamePattern && preg_match($strFilenamePattern, $item))) {
                    $result[] = $item;
                }
            }
        }

        return $result;
    }
public static function listFilesInFolder($strPath, $blnSkipFolders = true, $strFilenamePattern = null)
    {
        // strip off the trailing slash if it's there
        if ($strPath[strlen($strPath) - 1] == "/") {
            $strPath = substr($strPath, 0, -1);
        }

        $result = array();

        $originalSet = self::getFilesInFolderHelper($strPath);
        if (!$originalSet) {
            return $result;
        }    // empty directory, or directory does not exist

        foreach ($originalSet as $item) {
            $childPath = $strPath . "/" . $item;
            if (is_dir($childPath)) {
                $childItems = self::listFilesInFolder($childPath);
                foreach ($childItems as $child) {
                    $result[] = $item . "/" . $child;
                }
            }

            if (!$blnSkipFolders || !is_dir($childPath)) {
                if (!$strFilenamePattern || ($strFilenamePattern && preg_match($strFilenamePattern, $item))) {
                    $result[] = $item;
                }
            }
        }

        return $result;
    }
public static function listFilesInFolder ( $ strPath , $ blnSkipFolders = true , $ strFilenamePattern = null ) { // strip off the trailing slash if it's there if ( $ strPath [ strlen ( $ strPath ) - 1 ] == "/" ) { $ strPath = substr ( $ strPath , 0 , - 1 ) ; } $ result = array ( ) ; $ originalSet = self :: getFilesInFolderHelper ( $ strPath ) ; if ( ! $ originalSet ) { return $ result ; } // empty directory, or directory does not exist foreach ( $ originalSet as $ item ) { $ childPath = $ strPath . "/" . $ item ; if ( is_dir ( $ childPath ) ) { $ childItems = self :: listFilesInFolder ( $ childPath ) ; foreach ( $ childItems as $ child ) { $ result [ ] = $ item . "/" . $ child ; } } if ( ! $ blnSkipFolders || ! is_dir ( $ childPath ) ) { if ( ! $ strFilenamePattern || ( $ strFilenamePattern && preg_match ( $ strFilenamePattern , $ item ) ) ) { $ result [ ] = $ item ; } } } return $ result ; }
Traverse a particular path and get a list of files and folders
underneath that path. Optionally, also provide a regular
expression that specifies the pattern that the returned files must match.

@param    string $strPath full path to the folder to be processed
@param    boolean $blnSkipFolders If this is set to true, only the FILES will be returned - not the folders.
@param    string $strFilenamePattern : optional string; regular expression that the files must match in order to be returned. If it's not set, all files in that folder will be returned.

@return array
Traverse a particular path and get a list of files and folders underneath that path . Optionally also provide a regular expression that specifies the pattern that the returned files must match .