コード例 #1
0
 /**
  * Download $remote_path directory recursive as $local_path.
  * 
  * @throws
  * @param string $remote_path
  * @param string $local_path
  * @return vector<string>
  */
 public function getDir($remote_path, $local_path)
 {
     $entries = $this->ls($remote_path);
     Dir::create($local_path, 0, true);
     foreach ($entries as $path => $info) {
         if ($info['type'] === 'f') {
             $this->get($path, $local_path . '/' . $info['name']);
         } else {
             if ($info['type'] === 'l') {
                 if (FSEntry::isLink($local_path . '/' . $info['name'], false)) {
                     File::remove($local_path . '/' . $info['name']);
                 }
                 print "link: " . $info['link'] . " - " . $local_path . '/' . $info['name'] . "\n";
                 FSEntry::link($info['link'], $local_path . '/' . $info['name'], false);
             } else {
                 if ($info['type'] === 'd') {
                     $this->getDir($path, $local_path . '/' . $info['name']);
                 }
             }
         }
     }
 }
コード例 #2
0
 /**
  * Remove directory.
  *
  * @param string $path
  * @param boolean $must_exist (default = true)
  */
 public static function remove($path, $must_exist = true)
 {
     if ($path != trim($path)) {
         throw new Exception('no leading or trailing whitespace allowed in path', $path);
     }
     if (substr($path, -1) == '/') {
         throw new Exception('no trailing / allowed in path', $path);
     }
     if (!$must_exist && !FSEntry::isDir($path, false)) {
         return;
     }
     if (FSEntry::isLink($path, false)) {
         FSEntry::unlink($path);
         return;
     }
     $entries = Dir::entries($path);
     foreach ($entries as $entry) {
         if (FSEntry::isFile($entry, false)) {
             File::remove($entry);
         } else {
             Dir::remove($entry);
         }
     }
     if (!rmdir($path) || FSEntry::isDir($path, false)) {
         throw new Exception('remove directory failed', $path);
     }
 }