+----------------------------------------------------------
判断目录是否为空
+----------------------------------------------------------
+----------------------------------------------------------
+----------------------------------------------------------
public isEmpty ( $directory ) |
function elimina_immagine() { $image_name = Params::get("image_name"); $id_prodotto_servizio = Params::get("id_prodotto_servizio"); $product_image_dir = new Dir(self::PRODUCT_IMAGE_DIR . "/" . $id_prodotto_servizio); $product_image_file = $product_image_dir->newFile($image_name); ImagePicker::delete_image_thumbnails($product_image_file); //elimino la riga associata all'immagine $peer = new ImmagineProdottoServizioPeer(); $peer->id_prodotto_servizio__EQUALS($id_prodotto_servizio); $peer->nome_immagine__EQUALS($image_name); $elenco_immagini_prodotto_servizio = $peer->find(); foreach ($elenco_immagini_prodotto_servizio as $img) { $peer->delete($img); } $product_image_file->delete(); if ($product_image_dir->isEmpty()) { $product_image_dir->delete(); } return Redirect::success(); }
function execute() { $dir = $this->dir; $force = $this->force; if (self::$dummy_mode) { echo "Rmdir : " . self::$root_dir->getPath() . $dir . "<br />"; return; } $d = new Dir(self::$root_dir->getPath() . $dir); if (!$d->isEmpty() && $force || $d->isEmpty()) { $d->delete(true); } }
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(); } }
/** * 获取目录信息 * @param $path */ function ImgList($path) { $dir = new Dir($path); if ($dir->isEmpty($path)) { return false; } $dirlist = $dir->toArray(); return $dirlist; }
function testDeleteRecursive() { $d = new Dir("/" . FRAMEWORK_CORE_PATH . "tests/io/delete_test_dir/"); $this->assertTrue($d->exists(), "La cartella dal eliminare non esiste!!"); $this->assertTrue($d->isEmpty(), "La cartella da popolare non e' vuota!!"); $the_dir = $d->newSubdir("the_dir"); $blabla = $the_dir->newFile("blabla.ini"); $blabla->setContent("[section]\n\nchiave=valore\n\n"); $hidden_test = $the_dir->newSubdir("hidden_test"); $htaccess = $hidden_test->newFile(".htaccess"); $htaccess->setContent("RewriteEngine on\n\n"); $prova = $hidden_test->newFile("prova.txt"); $prova->setContent("Questo e' un file con un testo di prova"); $the_dir->delete(true); $this->assertFalse($the_dir->exists(), "La directory non e' stata eliminata!!"); $this->assertTrue($d->isEmpty(), "Il contenuto della cartella non e' stato rimosso completamente!!"); }
/** * * Returns the verified storage folder. If it does not exists, it is created. * * @return \Mbcraft\Piol\Dir the directory, as a \Mbcraft\Piol\Dir instance, pointing to the verified storage. * @throws \Mbcraft\Piol\IOException if the storage root does not exists or is not valid. * * @api */ public static function getProtectedStorage() { $protected_storage_dir = new Dir(self::$storage_root); if (!$protected_storage_dir->exists()) { throw new IOException("The storage folder does not exist : " . self::$storage_root); } if (!$protected_storage_dir->isWritable()) { throw new IOException("The storage folder is not readable and writable : " . self::$storage_root); } $results = $protected_storage_dir->listElements(); if (count($results[0]) == 0 && count($results[1]) <= 1) { if ($protected_storage_dir->isEmpty()) { $protected_storage_dir->newRandomSubdir(); } return $protected_storage_dir->getUniqueSubdir(); } else { throw new IOException("The storage root folder is invalid : it must contain at most just one folder."); } }
public function rmdir($dir, $force = false) { if (self::$dummy_mode) { echo "Rmdir : " . self::$root_dir->getPath() . $dir . "<br />"; return; } $d = new Dir(self::$root_dir->getPath() . $dir); if (!$d->isEmpty() && $force || $d->isEmpty()) { $d->delete(true); } }
static function delete_image_thumbnails($path) { if ($path instanceof File) { $image_file = $path; } else { $image_file = new File($path); } $image_dir = $image_file->getDirectory(); $full_cache_dir = new Dir(self::THUMBNAILS_DIR . $image_dir->getPath()); $folders = $full_cache_dir->listFolders(); foreach ($folders as $f) { $image_thumb = $f->newFile($image_file->getFilename()); if ($image_thumb->exists()) { $image_thumb->delete(); } if ($f->isEmpty()) { $f->delete(); } } if ($full_cache_dir->isEmpty()) { $full_cache_dir->delete(); } }
private static function get_verified_storage() { $protected_storage_dir = new Dir(self::$storage_root); if (!$protected_storage_dir->exists()) { throw new IOException("La cartella dello storage non esiste : " . self::$storage_root); } if (count($protected_storage_dir->listFiles()) > 1) { throw new IOException("Lo storage non è valido."); } if ($protected_storage_dir->isEmpty()) { $protected_storage_dir->newRandomSubdir(); } return $protected_storage_dir->getSingleSubdir(); }