コード例 #1
0
ファイル: FolderReader.php プロジェクト: josegamboa/FileTree
 /**
  * (PHP 5 &gt;= 5.3.0 )<br/>
  * Get array of files, using the currently path
  * @return Boolean true if the reading was ok , false if has  errors.
  */
 public function readFolder()
 {
     $read = false;
     if (file_exists($this->rootPath)) {
         $read = true;
         $files = scandir($this->rootPath);
         natcasesort($files);
         if (count($files) > 0) {
             // All dirs
             foreach ($files as $file) {
                 //discard folders
                 if ($file == '.' || $file == '..') {
                     continue;
                 }
                 $path = $this->rootPath . "/" . $file;
                 if (is_dir($path)) {
                     $folderInfo = new FolderInfo();
                     $folderInfo->setName($file);
                     $folderInfo->setPath($path . "/");
                     $this->folderItemList->setItem($folderInfo);
                 }
             }
             $this->arrayAllFiles["folders"] = $this->folderItemList;
             // All files
             foreach ($files as $file) {
                 //dicart files
                 if ($file == '.' || $file == '..') {
                     continue;
                 }
                 $path = $this->rootPath . "/" . $file;
                 if (file_exists($path) && !is_dir($path)) {
                     $fileInfo = new FileInfo($path);
                     if (!$this->isFilterExtension($fileInfo->getExt())) {
                         $this->fileItemList->setItem($fileInfo);
                     }
                 }
             }
             $this->arrayAllFiles["files"] = $this->fileItemList;
         }
     }
     return $read;
 }