/** * 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 */ 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); } return $result; }
/** * Change group permission recursive * * @param string $filename * @param int $fileOctal - ex. 0644 * @param int $dirOctal - ex. 0755 * * @return bool */ protected function chgrpRecurse($path, $group) { if (!file_exists($path)) { return false; } if (!is_dir($path)) { return $this->chgrpReal($path, $group); } $result = $this->chgrpReal($path, $group); $allFiles = $this->getFileManager()->getFileList($path); foreach ($allFiles as $item) { $result &= $this->chgrpRecurse($path . Utils\Util::getSeparator() . $item, $group); } return (bool) $result; }