예제 #1
0
if(!class_exists('Eden_Folder')){class Eden_Folder extends Eden_Path{public static function i(){return self::_getMultiple(__CLASS__);}public function create($chmod=0755){if(!is_int($chmod) || $chmod < 0 || $chmod > 777){Eden_Folder_Error::i(Eden_Folder_Exception::CHMOD_IS_INVALID)->trigger();}if(!is_dir($this->_data)){mkdir($this->_data,$chmod,true);}return $this;}public function getFiles($regex=NULL,$recursive=false){$error=Eden_Folder_Error::i()->argument(1,'string','null')->argument(2,'bool');$this->absolute();$files=array();if ($handle=opendir($this->_data)){while (false !==($file=readdir($handle))){if(filetype($this->_data.'/'.$file)=='file' && (!$regex || preg_match($regex,$file))){$files[]=Eden_File::i($this->_data.'/'.$file);}else if($recursive && $file !='.' && $file !='..' && filetype($this->_data.'/'.$file)=='dir'){$subfiles=self::i($this->_data.'/'.$file);$files=array_merge($files,$subfiles->getFiles($regex,$recursive));}}closedir($handle);}return $files;}public function getFolders($regex=NULL,$recursive=false){Eden_Folder_Error::i()->argument(1,'string','null')->argument(2,'bool');$this->absolute();$folders=array();if($handle=opendir($this->_data)){while (false !==($folder=readdir($handle))){if($folder !='.' && $folder !='..' && filetype($this->_data.'/'.$folder)=='dir' && (!$regex || preg_match($regex,$folder))){$folders[]=Eden_Folder::i($this->_data.'/'.$folder);if($recursive){$subfolders=Eden_Folder::i($this->_data.'/'.$folder);$folders=array_merge($folders,$subfolders->getFolders($regex,$recursive));}}}closedir($handle);}return $folders;}public function getName(){$pathArray=$this->getArray();return array_pop($pathArray);}public function isFile(){return file_exists($this->_data);}public function isFolder($path=NULL){Eden_Folder_Error::i()->argument(1,'string','null');if(is_string($path)){return is_dir($this->_data.'/'.$path);}return is_dir($this->_data);}public function remove(){$path=$this->absolute();if(is_dir($path)){rmdir($path);}return $this;}public function removeFiles($regex=NULL){Eden_Folder_Error::i()->argument(1,'string','null');$files=$this->getFiles($regex);if(empty($files)){return $this;}foreach($files as $file){$file->remove();}return $this;}public function removeFolders($regex=NULL){Eden_Folder_Error::i()->argument(1,'string','null');$this->absolute();$folders=$this->getFolders($regex);if(empty($folders)){return $this;}foreach($folders as $folder){$folder->remove();}return $this;}public function truncate(){$this->removeFolders();$this->removeFiles();return $this;}}class Eden_Folder_Error extends Eden_Error{public static function i($message=NULL,$code=0){$class=__CLASS__;return new $class($message,$code);}}}
예제 #2
0
파일: folder.php 프로젝트: annaqin/eden
 /**
  * Returns a list of folders given the path and optionally the regular expression
  *
  * @param string regular expression
  * @return array
  */
 public function getFolders($regex = NULL, $recursive = false)
 {
     //argument test
     Eden_Folder_Error::i()->argument(1, 'string', 'null')->argument(2, 'bool');
     //argument 2 must be a boolean
     $this->absolute();
     $folders = array();
     if ($handle = opendir($this->_data)) {
         //walk the directory
         while (false !== ($folder = readdir($handle))) {
             // If this is infact a directory
             //and if it matches the regex
             if ($folder != '.' && $folder != '..' && filetype($this->_data . '/' . $folder) == 'dir' && (!$regex || preg_match($regex, $folder))) {
                 //add it
                 $folders[] = Eden_Folder::i($this->_data . '/' . $folder);
                 if ($recursive) {
                     $subfolders = Eden_Folder::i($this->_data . '/' . $folder);
                     $folders = array_merge($folders, $subfolders->getFolders($regex, $recursive));
                 }
             }
         }
         closedir($handle);
     }
     return $folders;
 }
예제 #3
0
 public function getFolders($regex = NULL, $recursive = false)
 {
     Eden_Folder_Error::i()->argument(1, 'string', 'null')->argument(2, 'bool');
     $this->absolute();
     $folders = array();
     if ($handle = opendir($this->_data)) {
         while (false !== ($folder = readdir($handle))) {
             if ($folder != '.' && $folder != '..' && filetype($this->_data . '/' . $folder) == 'dir' && (!$regex || preg_match($regex, $folder))) {
                 $folders[] = Eden_Folder::i($this->_data . '/' . $folder);
                 if ($recursive) {
                     $subfolders = Eden_Folder::i($this->_data . '/' . $folder);
                     $folders = array_merge($folders, $subfolders->getFolders($regex, $recursive));
                 }
             }
         }
         closedir($handle);
     }
     return $folders;
 }