Rename a file.

@param string $path
@param string $newPath

@return bool
510050
public function rename($path, $newPath)
    {
        try {
            return (bool) $this->api->rename($path, $newPath);
        } catch (\Exception $e) {
            return false;
        }
    }
54802
def rename_file(old, new, path=None):
    
    cwd = os.getcwd()
    try:
        if path:
            os.chdir(path)
    except OSError:
        raise
    try:
        os.rename(old, new)
        os.chdir(cwd)
        return True
    except OSError:
        os.chdir(cwd)
        raise
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;
    }
366209
public static function rename_dir($path, $new_path, $source_area = null, $target_area = null)
	{
		return static::rename($path, $new_path, $source_area, $target_area);
	}
513466
public function moveFile($oldPath, $newPath, $isRename = false)
    {
        $oldPath = self::validatePath($oldPath);
        $fullOldPath = $this->getMediaPath($oldPath);

        $newPath = self::validatePath($newPath);
        $fullNewPath = $this->getMediaPath($newPath);

        return $this->getStorageDisk()->move($fullOldPath, $fullNewPath);
    }
203632
public function rename($key, $newkey) {
        $keys = [$key, $newkey];
        return $this->returnCommand(['RENAME'], $keys, $keys);
    }
417185
public function rename($dir, $path, $new, $type = 'file'){
    if ( ($cfg = $this->dir($dir)) &&
      ($root = $this->get_root_path($dir)) &&
      bbn\str::check_filename($new)
    ){
      $is_file = $type === 'file';
      $wtype = $is_file ? 'file' : 'directory';
      $pi = pathinfo($path);
      $files = [];
      if ( $pi['filename'] !== $new ){
        if ( !empty($cfg['tabs']) ){
          $ext = false;
          foreach ( $cfg['tabs'] as $t ){
            if ( empty($t['fixed']) ){
              // MVC tab's path
              $real = $root . $t['path'];
              if ( $pi['dirname'] !== '.' ){
                $real .= $pi['dirname'] . '/';
              }
              if ( $is_file ){
                foreach ( $t['extensions'] as $e ){
                  $real_new = $real . $new . '.' . $e['ext'];
                  $real_ext = $real . $pi['filename'] . '.' . $e['ext'];
                  if ( file_exists($real_ext) ){
                    if ( !file_exists($real_new) ){
                      $ext = empty($ext) ? $e['ext'] : $ext;
                      $files[$real_ext] = $real_new;
                      if ( $t['url'] === 'php' ){
                        $change_perm = [
                          'old' => $real_ext,
                          'new' => $real_new,
                          'type' => 'file'
                        ];
                      }
                    }
                    else {
                      $this->error("The file $real_new is already exists.");
                      return false;
                    }
                  }
                }
                if ( !empty($t['default']) ){
                  $file_url = $this->real_to_url($real_ext);
                  $file_new_url = $this->real_to_url($real_new);
                }
              }
              else {
                $real_new = $real . $new;
                $real .= $pi['filename'];
                if ( file_exists($real) ){
                  if ( !file_exists($real_new) ){
                    $files[$real] = $real_new;
                    if ( $t['url'] === 'php' ){
                      $change_perm = [
                        'old' => $real,
                        'new' => $real_new,
                        'type' => 'dir'
                      ];
                    }
                  }
                  else {
                    $this->error("The directory $real_new is already exists.");
                    return false;
                  }
                }
              }
              if ( !empty($t['default']) ){
                $file_new = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new;
                $file_new_name = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new;
              }
            }
          }
        }
        else {
          $real = $root . $path;
          $real_new = $root . $new . ($is_file ?  '.' . $pi['extension'] : '');
          if ( file_exists($real) ){
            if ( !file_exists($real_new) ){
              $files[$real] = $real_new;
            }
            else {
              $this->error("The $wtype $real_new is already exists.");
              return false;
            }
            if ( $is_file ){
              $file_url = $this->real_to_url($real);
              $file_new_url = $this->real_to_url($real_new);
              $file_new = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new . '.' . $pi['extension'];
              $file_new_name = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new . '.' . $pi['extension'];
            }
            else {
              $file_new = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new;
              $file_new_name = (($pi['dirname'] !== '.') ? $pi['dirname'] . '/' : '') . $new;
            }
          }
        }

        foreach ( $files as $s => $d ){
          if ( !rename($s, $d) ){
            $this->error("Impossible to rename the $wtype: $s -> $d");
            return false;
          }
          if ( is_file($s) ){
            // Remove file's options
            $this->options->remove($this->options->from_code($this->real_to_id($s), $this->_files_pref()));
          }
          else {
            $this->rem_dir_opt($s);
          }
        }

        // Change permission
        if ( !empty($change_perm) ){
          $this->change_perm_by_real($change_perm['old'], $change_perm['new'], $change_perm['type']);
        }

        return [
          'file_url' => $file_url,
          'file_new_url' => $file_new_url,
          'file_new' => $file_new,
          'file_new_name' => $file_new_name,
          'file_new_ext' => $ext
        ];
      }
      $this->error("The old name and the new name are identical.");
      return false;
    }
  }
973243
public function rename($path, $newpath)
    {
        $newpath = static::normalizerPath($newpath);

        $this->writeStream($newpath, $this->readStream($path)['stream'], new Config() );

        $this->delete($path);

        return true;
    }
777394
def rename(path):
    """"""

    new_path = prompt(path)

    if path != new_path:
        try:
            from shutil import move
        except ImportError:
            from os import rename as move

        move(path, new_path)

    return new_path
131781
public function move($nameold,$pathnew,$path){
        if($this->validNameFile($nameold,false) && preg_match_all("#^/{1}$|^/[a-z0-9A-Z]{1}([a-z0-9A-Z-_/])*(/|[a-z0-9A-Z-_]{1,})+$#",$pathnew) > 0){
            $nameold = $this->clearNameFile($nameold);
            $fullpath = $this->sanitizeNameFolder($this->getFullPath().$path,true);
            $fullpathnew = $this->sanitizeNameFolder($this->getFullPath().$pathnew,true);
            if( $this->config['debug'] ) $this->_log('$fullpath - '.$fullpath);
            if( $this->config['debug'] ) $this->_log('$fullpathnew - '.$fullpathnew);
            if( $this->config['debug'] ) $this->_log('$fullpath/$nameold - '.$fullpath.'/'.$nameold);
            if( $this->config['debug'] ) $this->_log('$fullpathnew/$nameold - '.$fullpathnew.'/'.$nameold);

            if($fullpath == $fullpathnew || $fullpath.'/'.$nameold==$fullpathnew.'/'.$nameold){
                if( $this->config['debug'] ) $this->_log('$path == $pathnew Equals');
                $result = array("query"=>"BE_MOVE_PATH_NOT_VALID","params"=>array());
                $this->setInfo(array("msg"=>$result, "status"=>0));
                return;
            }elseif(strpos($fullpathnew.'/'.$nameold,$fullpath.'/'.$nameold.'/')!==false ){
                if( $this->config['debug'] ) $this->_log('$pathnew internal of source - '.$pathnew);
                $result = array("query"=>"BE_MOVE_PATH_NOT_VALID","params"=>array());
                $this->setInfo(array("msg"=>$result, "status"=>0));
                return;
            }elseif(strpos($fullpath.'/'.$nameold,$fullpathnew.'/'.$nameold.'/')!==false ){
                if( $this->config['debug'] ) $this->_log('$pathnew not moved in same folder - '.$pathnew);
                $result = array("query"=>"BE_MOVE_PATH_NOT_VALID","params"=>array());
                $this->setInfo(array("msg"=>$result, "status"=>0));
                return;
            }
            $file = new Filesystem;
            if($file->exists($fullpath.'/'.$nameold)){
                if(is_dir($fullpath.'/'.$nameold)){
                    if($file->exists($fullpathnew.'/'.$nameold)===false){
                        if($file->exists($fullpathnew)==false){
                            $file->mkdir($fullpathnew);
                        }
                        $file->rename($fullpath.'/'.$nameold,$fullpathnew.'/'.$nameold);
                        $result = array("query"=>"BE_MOVE_MOVED","params"=>array());
                        $fullpathnew_result = $this->sanitizeNameFolder($pathnew.'/'.$nameold,true);
                        $this->setInfo(array("msg"=>$result,"data"=>array("namefile" => $fullpathnew_result)));
                    }else{
                        $result = array("query"=>"BE_MOVE_FOLDER_EXISTED","params"=>array());
                        $this->setInfo(array("msg"=>$result, "status"=>0));
                    }

                }elseif(is_file($fullpath.'/'.$nameold)){
                    if($this->validExt($nameold)){
                        if($file->exists($fullpathnew.'/'.$nameold)===false){
                            if($file->exists($fullpathnew)==false){
                                $file->mkdir($fullpathnew);
                            }
                            $file2 = new \SplFileInfo($fullpath.'/'.$nameold);
                            if(in_array($file2->getExtension(), $this->config['images']['images_ext'])){
                                $filename = $file2->getFilename();
                                foreach ($this->config['images']['resize'] as $key => $value) {
                                    $image_info = $this->imageSizeName($path,$filename,$value);
                                    $filename_old = $image_info['name'];
                                    $fullpaththumb_name = $this->getFullPath().'/'.$this->config['folder_thumb'].$path.$filename_old;
                                    $file->remove($fullpaththumb_name);
                                }
                            }
                            $file->rename($fullpath.'/'.$nameold,$fullpathnew.'/'.$nameold);
                            $result = array("query"=>"BE_MOVE_MOVED","params"=>array());
                            $fullpathnew_result = $this->sanitizeNameFolder($pathnew.'/'.$nameold,true);
                            $this->setInfo(array("msg"=>$result,"data"=>array("namefile" => $fullpathnew_result)));
                        }else{
                            $result = array("query"=>"BE_MOVE_EXISTED","params"=>array());
                            $this->setInfo(array("msg"=>$result, "status"=>0));
                        }
                    }else{
                        $result = array("query"=>"BE_MOVE_FILENAME_NOT_VALID","params"=>array());
                        $this->setInfo(array("msg"=>$result, "status"=>0));
                    }
                }
            }else{
                $result = array("query"=>"BE_MOVE_NOT_EXISTS","params"=>array());
                $this->setInfo(array("msg"=>$result, "status"=>0));
            }
        }else{
            $result = array("query"=>"BE_MOVE_FILENAME_NOT_VALID","params"=>array());
            $this->setInfo(array("msg"=>$result, "status"=>0));
        }
    }
914175
public function renameFileInFileSystem(File $originFile, File $newFile)
	{
		$originFilePath = $this->getFilesystemPath($originFile);
		
		if ( ! file_exists($originFilePath)) {
			// silently exit to allow to rename physically non existing files
			return false;
		}

		$newPath = $this->getFilesystemPath($newFile);
		
		if (! rename($originFilePath, $newPath)) {
			throw new Exception\RuntimeException('File renaming failed');
		}

		if ($originFile instanceof Image) {
			
			$sizes = $originFile->getImageSizeCollection();
			
			foreach ($sizes as $size) {
				
				$sizeName = $size->getName();
				
				$newPath = $this->getImagePath($newFile, $sizeName);
				
				$currentPath = $this->getImagePath($originFile, $sizeName);
			
				rename($currentPath, $newPath);
			}
		}
	}
738520
public function copy(string $newFilePath, bool $overwrite = true): self
    {
        $newFilePath = normalize_path($newFilePath);

        if ($overwrite || !is_file($newFilePath)) {
            if (copy($this->path, $newFilePath)) {
                return new self($newFilePath);
            }
            throw new FileException('Cannot copy file to the new file path ('.$newFilePath.') for unknown reasons');
        }
        throw new FileException('Cannot copy file, because the new file path ('.$newFilePath.') already exists', FileException::ALREADY_EXIST);
    }
671341
public function copy($path, $newpath)
    {
        $url = cloudinary_url_internal($path);
        $result = Uploader::upload($url, ['public_id' => $newpath]);

        return is_array($result) ? $result['public_id'] == $newpath : false;
    }
700738
@Override
  public int rename(String oldPath, String newPath) {
    final AlluxioURI oldUri = mPathResolverCache.getUnchecked(oldPath);
    final AlluxioURI newUri = mPathResolverCache.getUnchecked(newPath);
    LOG.trace("rename({}, {}) [Alluxio: {}, {}]", oldPath, newPath, oldUri, newUri);

    try {
      mFileSystem.rename(oldUri, newUri);
      synchronized (mOpenFiles) {
        if (mOpenFiles.contains(PATH_INDEX, oldPath)) {
          OpenFileEntry oe = mOpenFiles.getFirstByField(PATH_INDEX, oldPath);
          oe.setPath(newPath);
        }
      }
    } catch (FileDoesNotExistException e) {
      LOG.debug("Failed to rename {} to {}, file {} does not exist", oldPath, newPath, oldPath);
      return -ErrorCodes.ENOENT();
    } catch (FileAlreadyExistsException e) {
      LOG.debug("Failed to rename {} to {}, file {} already exists", oldPath, newPath, newPath);
      return -ErrorCodes.EEXIST();
    } catch (Throwable t) {
      LOG.error("Failed to rename {} to {}", oldPath, newPath, t);
      return AlluxioFuseUtils.getErrorCode(t);
    }

    return 0;
  }
1027978
public static void renamePath(FileSystem fs, Path oldName, Path newName) throws IOException {
    renamePath(fs, oldName, newName, false);
  }
1143725
public function rename($oldName = null, $newName = null)
        {
            // attempt rename
            if(ftp_rename(static::$_stream, $oldName, $newName)) {
                // success
                return true;
            // fail
            } else {
                static::$error = "Failed to rename file \"{$oldName}\"";
                return false;
            }
        }
727973
public function rename($oldname, $newname)
    {
        $oldname = $this->pathRoot.ltrim($oldname, "/");
        $newname = $this->pathRoot.ltrim($newname, "/");
        return rename($oldname, $newname);
    }