Rename file.

@param String $bucketName
@param String $bucketId       //For feature compatibility
@param String $fileName
@param String $targetBucketId
@param String $newFileName
@param bool   $private

@return bool
7118
public function rename($bucketName, $bucketId, $fileName, $targetBucketId, $newFileName, $private = false)
    {
        $data = $this->get($bucketName, $fileName, $private, false);
        if (is_array($data) && array_key_exists('x-bz-file-id', $data['headers'])) {
            $result = $this->insert($targetBucketId, $data['content'], $newFileName);
            if ($result === false) {
                return false;
            }
            $response = $this->client->b2DeleteFileVersion($this->apiURL, $this->token, $data['headers']['x-bz-file-id'], $fileName);

            return $response->isOk();
        }

        return false;
    }
929321
protected function startLargeFile($fileName, $contentType, $bucketId)
    {
        $response = $this->generateAuthenticatedClient([
            'fileName'      => $fileName,
            'contentType'   => $contentType,
            'bucketId'      => $bucketId,
        ])->request('POST', '/b2_start_large_file');

        return $response;
    }
821752
public static String createNewBucketName(String accessKeyId,
                                             String spaceId) {
        String bucketName = accessKeyId + "." + spaceId;
        bucketName = bucketName.toLowerCase();
        bucketName = bucketName.replaceAll("[^a-z0-9-.]", "-");

        // Remove duplicate separators (. and -)
        while (bucketName.contains("--") || bucketName.contains("..")
               || bucketName.contains("-.") || bucketName.contains(".-")) {
            bucketName = bucketName.replaceAll("[-]+", "-");
            bucketName = bucketName.replaceAll("[.]+", ".");
            bucketName = bucketName.replaceAll("-[.]", "-");
            bucketName = bucketName.replaceAll("[.]-", ".");
        }

        if (bucketName.length() > 63) {
            bucketName = bucketName.substring(0, 63);
        }
        while (bucketName.endsWith("-") || bucketName.endsWith(".")) {
            bucketName = bucketName.substring(0, bucketName.length() - 1);
        }
        return bucketName;
    }
98937
public function rename($fileID, $name)
    {
        $data = [
            'file_id' => $fileID,
            'name'    => $name
        ];

        return $this->post('files/rename', $data, \true);
    }
676955
public function rename($path, $originalFileName, $newFileName)
    {
        $path = $this->cleanFolder($path);
        $nameName = $path.DIRECTORY_SEPARATOR.$newFileName;
        if ($this->disk->exists($nameName)) {
            $this->errors[] = 'The file "'.$newFileName.'" already exists in this folder.';

            return false;
        }

        return $this->disk->getDriver()->rename(($path.DIRECTORY_SEPARATOR.$originalFileName), $nameName);
    }
910306
private void renameFile(File source, File target) {
        if (!source.exists()) {
            // don't do anything if the source file doesn't exist
            return;
        }
        if (target.exists()) {
            target.delete();
        }
        boolean rc = source.renameTo(target);
        if (!rc) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, getFileName() + ": Unable to rename " + source + " to " + target);
            }
        }
    }
1224902
function RenameFile($type, $dir, $filename, $newname)
    {
        $dir = $this->AccessDir($dir, $type);
        if (!$dir)
        {
            return false;
        }

        $filename = trim($filename);

        if (empty($filename))
        {
            return 'error';
        }

        if (!is_dir($dir . '/.thumbs'))
        {
            return 'error';
        }

        $dbfile = $dir . '/.thumbs/.db';
        if (is_file($dbfile))
        {
            $dbfilehandle = fopen($dbfile, "r");
            $dblength = filesize($dbfile);
            if ($dblength > 0)
            {
                $dbdata = fread($dbfilehandle, $dblength);
            }
            else
            {
                $dbdata = '';
            }
            fclose($dbfilehandle);
        }
        else
        {
            return 'error';
        }

        $files = unserialize($dbdata);

        foreach ($files as $file => $fdata)
        {
            if ($file == $filename)
            {
                $files[$file]['general']['name'] = $newname;
                break;
            }
        }

        $dbfilehandle = fopen($dbfile, "w");
        fwrite($dbfilehandle, serialize($files));
        fclose($dbfilehandle);

        return 'ok';
    }
1256046
public function rename($path, $newPath)
    {
        if ($this->client->copyObject($this->bucket, $path, $this->bucket, $newPath) !== null) {
            $result = $this->client->deleteObject($this->bucket, $path);
            if (!is_null($result)) {
                return true;
            }
        }

        return false;
    }
901212
public function rename($sourceKey, $targetKey)
    {
        $this->init();

        list($sourceContainerName, $sourceKey) = $this->tokenizeKey($sourceKey);
        list($targetContainerName, $targetKey) = $this->tokenizeKey($targetKey);

        try {
            if ($this->multiContainerMode) {
                $this->createContainer($targetContainerName);
            }
            $this->blobProxy->copyBlob($targetContainerName, $targetKey, $sourceContainerName, $sourceKey);
            $this->blobProxy->deleteBlob($sourceContainerName, $sourceKey);

            return true;
        } catch (ServiceException $e) {
            $this->failIfContainerNotFound($e, sprintf('rename key "%s"', $sourceKey), $sourceContainerName);

            return false;
        }
    }
1107026
public function get($bucketName, $fileName, $private = false, $metadataOnly = false)
    {
        $token = null;
        if ($private == true) {
            $this->ensureAuthorized();
            $token = $this->token;
        }
        $response = $this->client->b2DownloadFileByName($this->downloadURL, $bucketName, $fileName, $token, $metadataOnly);
        if ($response->isOk(false)) {
            return array('headers' => $response->getHeaders(), 'content' => $response->getRawContent());
        }

        return false;
    }
326208
public function rename($oldName, $newName)
    {
        if (! ssh2_sftp_rename($this->sFtp, $oldName, $newName)) {
            throw new \RuntimeException('Name can not be changed');
        }
        return true;
    }
912902
protected function renameFile($path, $newName)
    {
        $newPath = pathinfo($path, PATHINFO_DIRNAME) . '/' . $newName;

        try {
            $success = rename($path, $newPath);

            // @codeCoverageIgnoreStart
        } catch (\Exception $e) {
            throw new CouldNotRetrieveRemoteFileException("Failed to rename '{$path}' to '{$newName}'", $e->getCode(), $e);
            // @codeCoverageIgnoreEnd
        }

        // @codeCoverageIgnoreStart
        if ( ! $success) {
            throw new CouldNotRetrieveRemoteFileException("Failed to rename '{$path}' to '{$newName}'");
        }
        // @codeCoverageIgnoreEnd

        return $newPath;
    }
487723
public function getAllZip($bucketName, array $filesName, $zipFileName, $private = false){
        $zip = new \ZipArchive();
        if ($zip->open($zipFileName, \ZipArchive::CREATE) === true) {
            foreach ($filesName as $file) {
                $content = $this->get($bucketName,$file,$private,false);
                if($content !== false){
                    try{
                        $zip->addFromString($file, $content["content"]);
                    }catch (\Exception $e){
                        return false;
                    }
                }
            }
            $zip->close();
        }else{
            return false;
        }
        return true;
    }
94034
public function renameFile($fileIndex, $newFileName)
    {
        $fileIndex = (int)$fileIndex;
        foreach ($this->positions as $position) {
            $source = $position->source;
            if ($source->fileIndex === $fileIndex) {
                $source->fileName = $newFileName;
            }
        }
    }
1219124
public function rename() {
    $token_header = $this->getOAuthTokenHeader(parent::WRITE_SCOPE);
    if ($token_header === false) {
      if (!$this->quiet) {
        trigger_error("Unable to acquire OAuth token.", E_USER_WARNING);
      }
      return false;
    }

    // Stat the from object to get the etag and content-type
    $http_response = $this->makeHttpRequest($this->url, "HEAD", $token_header);
    if ($http_response === false) {
      trigger_error("Unable to connect to Google Cloud Storage Service.",
                    E_USER_WARNING);
      return false;
    }
    $status_code = $http_response['status_code'];

    if ($status_code != HttpResponse::OK) {
      trigger_error(sprintf("Unable to rename: %s. Cloud Storage Error: %s",
                            sprintf("gs://%s%s",
                                    $this->to_bucket,
                                    $this->to_object),
                            HttpResponse::getStatusMessage($status_code)),
                    E_USER_WARNING);
      return false;
    }

    $copy_headers = [
      'x-goog-copy-source' =>
        sprintf("/%s%s", $this->from_bucket, $this->from_object),
      'x-goog-copy-source-if-match' =>
        $this->getHeaderValue('ETag', $http_response['headers']),
    ];

    // TODO: b/13132830: Remove once feature releases.
    if (!ini_get('google_app_engine.enable_additional_cloud_storage_headers')) {
      foreach (static::$METADATA_HEADERS as $key) {
        // Leave Content-Type since it has been supported.
        if ($key != 'Content-Type') {
          unset($this->context_options[$key]);
        }
      }
    }

    // Check if any metadata context options have been set and only copy values
    // below if one option needs to be changed.
    $is_meta = isset($this->context_options['metadata']);
    foreach (static::$METADATA_HEADERS as $key) {
      // Stop after first meta option found.
      $is_meta = $is_meta ?: isset($this->context_options[$key]);
      if ($is_meta) {
        break;
      }
    }

    // Metadata-directive applies to headers outside of x-goog-meta-* like
    // Content-Type. If any metadata changes are included in context then all
    // other meta data must be filled in since the metadata-directive will be
    // set to REPLACE and non-passed in values should remain the same.
    if ($is_meta) {
      $copy_headers['x-goog-metadata-directive'] = 'REPLACE';

      // Copy all meta data fields to preserve values when using REPLACE
      // directive. If a value exists in context_options it is given preference.
      foreach (static::$METADATA_HEADERS as $key) {
        if (isset($this->context_options[$key])) {
          $copy_headers[$key] = $this->context_options[$key];
        } else {
          $value = $this->getHeaderValue($key, $http_response['headers']);
          if ($value !== null) {
            $copy_headers[$key] = $value;
          }
        }
      }

      // Special case since metadata option converts to multiple headers, this
      // also handles copying over previous values if no new ones speicified.
      $metadata = isset($this->context_options['metadata']) ?
        $this->context_options['metadata'] :
        static::extractMetaData($http_response['headers']);
      foreach ($metadata as $key => $value) {
        $copy_headers['x-goog-meta-' . $key] = $value;
      }
    } else {
      $copy_headers['x-goog-metadata-directive'] = 'COPY';
    }

    if (array_key_exists("acl", $this->context_options)) {
      $acl = $this->context_options["acl"];
      if (in_array($acl, parent::$valid_acl_values)) {
        $copy_headers["x-goog-acl"] = $acl;
      } else {
        trigger_error(sprintf("Invalid ACL value: %s", $acl), E_USER_WARNING);
        return false;
      }
    }

    $to_url = $this->createObjectUrl($this->to_bucket, $this->to_object);
    $http_response = $this->makeHttpRequest($to_url, "PUT",
        array_merge($token_header, $copy_headers));

    if ($http_response === false) {
      trigger_error("Unable to copy source to destination.", E_USER_WARNING);
      return false;
    }

    $status_code = $http_response['status_code'];
    if ($status_code != HttpResponse::OK) {
      trigger_error(sprintf("Error copying to %s. Cloud Storage Error: %s",
                            sprintf("gs://%s%s",
                                    $this->to_bucket,
                                    $this->to_object),
                            HttpResponse::getStatusMessage($status_code)),
                    E_USER_WARNING);
      return false;
    }
    // Unlink the original file.
    $http_response = $this->makeHttpRequest($this->url,
                                            "DELETE",
                                            $token_header);

    if ($http_response === false) {
      trigger_error("Failed to delete the from cloud storage object.",
                    E_USER_WARNING);
      return false;
    }

    $status_code = $http_response['status_code'];
    if ($status_code !== HttpResponse::NO_CONTENT) {
      trigger_error(sprintf("Unable to unlink: %s. Cloud Storage Error: %s",
                            sprintf("gs://%s%s",
                                    $this->from_bucket,
                                    $this->from_object),
                            HttpResponse::getStatusMessage($status_code)),
                    E_USER_WARNING);
      return false;
    }

    clearstatcache(true, $this->createGcsFilename($this->from_bucket,
                                                  $this->from_object));
    clearstatcache(true, $this->createGcsFilename($this->to_bucket,
                                                  $this->to_object));
    return true;
  }
179737
public Blob updateBlob(String bucketName, String blobName) {
    // [START updateBlob]
    Map<String, String> newMetadata = new HashMap<>();
    newMetadata.put("key", "value");
    storage.update(BlobInfo.newBuilder(bucketName, blobName).setMetadata(null).build());
    Blob blob =
        storage.update(BlobInfo.newBuilder(bucketName, blobName).setMetadata(newMetadata).build());
    // [END updateBlob]
    return blob;
  }
517772
def clone_replace_name(self, new_name):
        
        if not self.bucket_name:
            raise InvalidUriError('clone_replace_name() on bucket-less URI %s' %
                                  self.uri)
        return BucketStorageUri(
            self.scheme, self.bucket_name, new_name, self.debug,
            suppress_consec_slashes=self.suppress_consec_slashes)