application/Espo/Core/Utils/File/Manager.php
public function getFileList($path, $recursively = false, $filter = '', $onlyFileType = null, $isReturnSingleArray = false)
    {
        $path = $this->concatPaths($path);

        $result = array();

        if (!file_exists($path) || !is_dir($path)) {
            return $result;
        }

        $cdir = scandir($path);
        foreach ($cdir as $key => $value)
        {
            if (!in_array($value,array(".", "..")))
            {
                $add = false;
                if (is_dir($path . Utils\Util::getSeparator() . $value)) {
                    if ($recursively || (is_int($recursively) && $recursively!=0) ) {
                        $nextRecursively = is_int($recursively) ? ($recursively-1) : $recursively;
                        $result[$value] = $this->getFileList($path . Utils\Util::getSeparator() . $value, $nextRecursively, $filter, $onlyFileType);
                    }
                    else if (!isset($onlyFileType) || !$onlyFileType){ /*save only directories*/
                        $add = true;
                    }
                }
                else if (!isset($onlyFileType) || $onlyFileType) { /*save only files*/
                    $add = true;
                }

                if ($add) {
                    if (!empty($filter)) {
                        if (preg_match('/'.$filter.'/i', $value)) {
                            $result[] = $value;
                        }
                    }
                    else {
                        $result[] = $value;
                    }
                }

            }
        }

        if ($isReturnSingleArray) {
            return $this->getSingeFileList($result, $onlyFileType, $path);
        }

        return $result;
    }
public function getFileList($path, $recursively = false, $filter = '', $onlyFileType = null, $isReturnSingleArray = false)
    {
        $path = $this->concatPaths($path);

        $result = array();

        if (!file_exists($path) || !is_dir($path)) {
            return $result;
        }

        $cdir = scandir($path);
        foreach ($cdir as $key => $value)
        {
            if (!in_array($value,array(".", "..")))
            {
                $add = false;
                if (is_dir($path . Utils\Util::getSeparator() . $value)) {
                    if ($recursively || (is_int($recursively) && $recursively!=0) ) {
                        $nextRecursively = is_int($recursively) ? ($recursively-1) : $recursively;
                        $result[$value] = $this->getFileList($path . Utils\Util::getSeparator() . $value, $nextRecursively, $filter, $onlyFileType);
                    }
                    else if (!isset($onlyFileType) || !$onlyFileType){ /*save only directories*/
                        $add = true;
                    }
                }
                else if (!isset($onlyFileType) || $onlyFileType) { /*save only files*/
                    $add = true;
                }

                if ($add) {
                    if (!empty($filter)) {
                        if (preg_match('/'.$filter.'/i', $value)) {
                            $result[] = $value;
                        }
                    }
                    else {
                        $result[] = $value;
                    }
                }

            }
        }

        if ($isReturnSingleArray) {
            return $this->getSingeFileList($result, $onlyFileType, $path);
        }

        return $result;
    }
public function getFileList ( $ path , $ recursively = false , $ filter = '' , $ onlyFileType = null , $ isReturnSingleArray = false ) { $ path = $ this -> concatPaths ( $ path ) ; $ result = array ( ) ; if ( ! file_exists ( $ path ) || ! is_dir ( $ path ) ) { return $ result ; } $ cdir = scandir ( $ path ) ; foreach ( $ cdir as $ key => $ value ) { if ( ! in_array ( $ value , array ( "." , ".." ) ) ) { $ add = false ; if ( is_dir ( $ path . Utils \ Util :: getSeparator ( ) . $ value ) ) { if ( $ recursively || ( is_int ( $ recursively ) && $ recursively != 0 ) ) { $ nextRecursively = is_int ( $ recursively ) ? ( $ recursively - 1 ) : $ recursively ; $ result [ $ value ] = $ this -> getFileList ( $ path . Utils \ Util :: getSeparator ( ) . $ value , $ nextRecursively , $ filter , $ onlyFileType ) ; } else if ( ! isset ( $ onlyFileType ) || ! $ onlyFileType ) { /*save only directories*/ $ add = true ; } } else if ( ! isset ( $ onlyFileType ) || $ onlyFileType ) { /*save only files*/ $ add = true ; } if ( $ add ) { if ( ! empty ( $ filter ) ) { if ( preg_match ( '/' . $ filter . '/i' , $ value ) ) { $ result [ ] = $ value ; } } else { $ result [ ] = $ value ; } } } } if ( $ isReturnSingleArray ) { return $ this -> getSingeFileList ( $ result , $ onlyFileType , $ path ) ; } return $ result ; }
Get a list of files in specified directory

@param string $path string - Folder path, Ex. myfolder
@param bool | int $recursively - Find files in subfolders
@param string $filter - Filter for files. Use regular expression, Ex. \.json$
@param bool $onlyFileType [null, true, false] - Filter for type of files/directories. If TRUE - returns only file list, if FALSE - only directory list
@param bool $isReturnSingleArray - if need to return a single array of file list

@return array
Get a list of files in specified directory