Exemple #1
0
 /**
  * Utility function to read the files in a directory
  * @param string The file system path
  * @param string A filter for the names
  * @param boolean Recurse search into sub-directories
  * @param boolean True if to prepend the full path to the file name
  * @param array folder names not to recurse into
  * @param boolean return a list of folders only (true)
  * @return array of file/folder names
  */
 public function fabrikReadDirectory($path, $filter = '.', $recurse = false, $fullpath = false, $aFolderFilter = array(), $foldersOnly = false)
 {
     $arr = array();
     if (!@is_dir($path)) {
         return $arr;
     }
     $handle = opendir($path);
     while ($file = readdir($handle)) {
         $dir = JPath::clean($path . '/' . $file);
         $isDir = is_dir($dir);
         if ($file != "." && $file != "..") {
             if (preg_match("/{$filter}/", $file)) {
                 if ($isDir && $foldersOnly || !$foldersOnly) {
                     if ($fullpath) {
                         $arr[] = trim(JPath::clean($path . '/' . $file));
                     } else {
                         $arr[] = trim($file);
                     }
                 }
             }
             $goDown = true;
             if ($recurse && $isDir) {
                 foreach ($aFolderFilter as $sFolderFilter) {
                     if (strstr($dir, $sFolderFilter)) {
                         $goDown = false;
                     }
                 }
                 if ($goDown) {
                     $arr2 = FabrikWorker::fabrikReadDirectory($dir, $filter, $recurse, $fullpath, $aFolderFilter, $foldersOnly);
                     $arrDiff = array_diff($arr, $arr2);
                     $arr = array_merge($arrDiff);
                 }
             }
         }
     }
     closedir($handle);
     asort($arr);
     return $arr;
 }