Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * 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 string $fileType [all, file, dir] - Filter for type of files/directories.
  * @param bool $isReturnSingleArray - if need to return a single array of file list
  *
  * @return array
  */
 public function getFileList($path, $recursively = false, $filter = '', $fileType = 'all', $isReturnSingleArray = false)
 {
     if (!file_exists($path)) {
         return false;
     }
     $result = array();
     $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, $fileType);
                 } else {
                     if (in_array($fileType, array('all', 'dir'))) {
                         $add = true;
                     }
                 }
             } else {
                 if (in_array($fileType, array('all', 'file'))) {
                     $add = true;
                 }
             }
             if ($add) {
                 if (!empty($filter)) {
                     if (preg_match('/' . $filter . '/i', $value)) {
                         $result[] = $value;
                     }
                 } else {
                     $result[] = $value;
                 }
             }
         }
     }
     if ($isReturnSingleArray) {
         return $this->getSingeFileList($result);
     }
     return $result;
 }
Exemplo n.º 3
0
 public function testGetSeparator()
 {
     $this->assertEquals(DIRECTORY_SEPARATOR, Util::getSeparator());
 }
Exemplo n.º 4
0
 /**
  * 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;
 }