function execute()
 {
     $file_or_folder = $this->file_or_folder;
     $force = $this->force;
     if (self::$dummy_mode) {
         echo "Removing : " . $file_or_folder . "<br />";
         return;
     }
     $root_dir_path = self::$root_dir->getPath();
     //se è una cartella elimino solo i file che sono anche nel modulo
     if (FileSystemUtils::isDir($this->module_dir->getPath() . $file_or_folder)) {
         $source_dir = new Dir($this->module_dir->getPath() . $file_or_folder);
         $target_dir = new Dir($root_dir_path . $file_or_folder);
         if (!$target_dir->exists()) {
             return;
         }
         $toremove_files = $source_dir->listFiles();
         foreach ($toremove_files as $elem) {
             if ($elem->isDir()) {
                 $this->remove($file_or_folder . $elem->getName() . DS);
             } else {
                 $this->remove($file_or_folder . $elem->getFilename());
             }
         }
         if ($target_dir->isEmpty()) {
             $target_dir->delete(false);
         }
     } else {
         $source_file = new File($this->module_dir->getPath() . $file_or_folder);
         $target_file = new File($root_dir_path . $file_or_folder);
         if (!$force && !$source_file->exists()) {
             return;
         }
         //se non esiste nel modulo non lo rimuovo
         $target_file->delete();
     }
 }
Esempio n. 2
0
File: Dir.php Progetto: mbcraft/piol
 /**
  * 
  * Finds all matching elements inside this folder.
  * 
  * @param int $mode Only the following values, specified as constants inside this class, can be used :
  *  MODE_FILES_ONLY, MODE_FOLDERS_ONLY, MODE_FILES_AND_FOLDERS.
  * @param array $myIncludes an array of regexp pattern of the elements to match using their full names.
  * @param boolean $deep if true the search is done recursively on all subfolders, otherwise only inside this one.
  * @return array an array of two arrays, with all the files that matched and all the directories that matched, 
  * as a \Mbcraft\Piol\File and \Mbcraft\Piol\Dir instances.
  * 
  * @api
  */
 public function findMatchingElements($mode, $myIncludes, $deep = false)
 {
     if (is_array($myIncludes)) {
         $includes = $myIncludes;
     } else {
         $includes = array($myIncludes);
     }
     $all_results = scandir($this->__full_path);
     $all_files = array();
     $all_dirs = array();
     foreach ($all_results as $element) {
         if ($element == "." || $element == "..") {
             //always skip . and ..
             continue;
         }
         $include = false;
         $done = false;
         foreach ($includes as $pt) {
             if (!$done && preg_match($pt, $element)) {
                 $include = true;
                 $done = true;
             }
         }
         $partial_path = $this->__path . $element;
         //è da aggiungere?
         if ($include) {
             if (($mode & self::MODE_FILES_ONLY) === self::MODE_FILES_ONLY && FileSystemUtils::isFile($partial_path)) {
                 $all_files[] = new File($partial_path);
                 continue;
             }
             if (($mode & self::MODE_FOLDERS_ONLY) === self::MODE_FOLDERS_ONLY && FileSystemUtils::isDir($partial_path)) {
                 $all_dirs[] = new Dir($partial_path);
             }
         }
         if ($deep && FileSystemUtils::isDir($partial_path)) {
             $d = new Dir($partial_path);
             $partial_results = $d->findMatchingElements($mode, $myIncludes, true);
             $all_files = array_merge($all_files, $partial_results[0]);
             $all_dirs = array_merge($all_dirs, $partial_results[1]);
         }
     }
     return array($all_files, $all_dirs);
 }
Esempio n. 3
0
 function findFiles($myIncludes)
 {
     if (is_array($myIncludes)) {
         $includes = $myIncludes;
     } else {
         $includes = array($myIncludes);
     }
     $all_results = scandir($this->__full_path);
     $all_dirs = array();
     $all_files = array();
     foreach ($all_results as $element) {
         $include = false;
         $done = false;
         foreach ($includes as $pt) {
             if (!$done && preg_match($pt, $element)) {
                 $include = true;
                 $done = true;
             }
         }
         //è da saltare?
         if ($include) {
             if ($this->isDir()) {
                 $partial_path = $this->__path . $element;
             }
             if (FileSystemUtils::isDir($this->__path . $element)) {
                 $all_dirs[] = new Dir($partial_path);
             } else {
                 if (FileSystemUtils::isFile($this->__path . DS . $element)) {
                     $all_files[] = new File($partial_path);
                 }
             }
         }
     }
     return array_merge($all_dirs, $all_files);
 }
Esempio n. 4
0
 function testIsDir()
 {
     $this->assertTrue(FileSystemUtils::isDir("/" . FRAMEWORK_CORE_PATH . "tests/io/"));
 }