コード例 #1
0
ファイル: FileSystem.php プロジェクト: ixtrum/file-manager
 /**
  * Delete file/directory
  *
  * @param string $path Path to file/directory
  *
  * @return boolean
  */
 public function delete($path)
 {
     if (is_dir($path)) {
         foreach (Finder::find("*")->in($path) as $item) {
             if ($item->isDir()) {
                 $this->delete($item->getRealPath());
             } else {
                 unlink($item->getPathName());
             }
         }
         if (!@rmdir($path)) {
             return false;
         }
     } else {
         unlink($path);
     }
     return true;
 }
コード例 #2
0
 /**
  * Get info about files
  *
  * @param string  $dir     Dir
  * @param array   $files   Files
  * @param boolean $iterate Iterate? (optional)
  *
  * @return array
  */
 private function getFilesInfo($dir, $files, $iterate = true)
 {
     $path = $this->getAbsolutePath($dir);
     $info = array("size" => 0, "dirCount" => 0, "filesCount" => 0);
     foreach ($files as $file) {
         $filePath = $path . DIRECTORY_SEPARATOR . $file;
         if (!is_dir($filePath)) {
             $info['size'] += $this->system->filesystem->getSize($filePath);
             $info['filesCount']++;
         } elseif ($iterate) {
             $info['dirCount']++;
             $items = Finder::find('*')->from($filePath);
             foreach ($items as $item) {
                 if ($item->isDir()) {
                     $info['dirCount']++;
                 } else {
                     $info['size'] += $this->system->filesystem->getSize($item->getPathName());
                     $info['filesCount']++;
                 }
             }
         }
     }
     return $info;
 }