A wrapper around {@link FileSystem#rename(Path, Path)} which throws {@link IOException} if
{@link FileSystem#rename(Path, Path)} returns False.
892
public static void renamePath(FileSystem fs, Path oldName, Path newName, boolean overwrite) throws IOException {
    if (!fs.exists(oldName)) {
      throw new FileNotFoundException(String.format("Failed to rename %s to %s: src not found", oldName, newName));
    }
    if (fs.exists(newName)) {
      if (overwrite) {
        HadoopUtils.moveToTrash(fs, newName);
      } else {
        throw new FileAlreadyExistsException(
            String.format("Failed to rename %s to %s: dst already exists", oldName, newName));
      }
    }
    if (!fs.rename(oldName, newName)) {
      throw new IOException(String.format("Failed to rename %s to %s", oldName, newName));
    }
  }
757981
def rename_file(self, old_path, new_path):
        
        self.log.debug("S3contents.GenericManager: Init rename of '%s' to '%s'", old_path, new_path)
        if self.file_exists(new_path) or self.dir_exists(new_path):
            self.already_exists(new_path)
        elif self.file_exists(old_path) or self.dir_exists(old_path):
            self.log.debug("S3contents.GenericManager: Actually renaming '%s' to '%s'", old_path,
                           new_path)
            self.fs.mv(old_path, new_path)
        else:
            self.no_such_entity(old_path)
1026848
public static void deleteDirIfExists(UnderFileSystem ufs, String path) throws IOException {
    if (ufs.isDirectory(path)
        && !ufs.deleteDirectory(path, DeleteOptions.defaults().setRecursive(true))) {
      throw new IOException("Folder " + path + " already exists but can not be deleted.");
    }
  }
1152117
public static void delete(String path) throws IOException {
    if (!Files.deleteIfExists(Paths.get(path))) {
      throw new IOException("Failed to delete " + path);
    }
  }
166851
@Override
  public boolean rename(final Path src, final Path dst) throws IOException {
    LOG.debug("rename from {} to {}", src, dst);
    if (src == null || dst == null) {
      LOG.debug("Source path and dest path can not be null");
      return false;
    }
    if (stocatorPath.isTemporaryPath(src)) {
      return true;
    }
    LOG.debug("Checking if source exists {}", src);
    if (!exists(src)) {
      LOG.debug("Source {} does not exists. Exit", src);
      return false;
    }
    final Path srcPath = storageClient.qualify(src);
    final Path dstPath = storageClient.qualify(dst);
    return storageClient.rename(hostNameScheme, srcPath.toString(), dstPath.toString());
  }
673799
@Override
  public boolean moveToTrash(Path path) throws IOException {
    Path fullyResolvedPath = path.isAbsolute() ? path : new Path(this.fs.getWorkingDirectory(), path);
    Path targetPathInTrash = PathUtils.mergePaths(this.trashLocation, fullyResolvedPath);

    if (!this.fs.exists(targetPathInTrash.getParent())) {
      this.fs.mkdirs(targetPathInTrash.getParent());
    } else if (this.fs.exists(targetPathInTrash)) {
      targetPathInTrash = targetPathInTrash.suffix("_" + System.currentTimeMillis());
    }

    return this.fs.rename(fullyResolvedPath, targetPathInTrash);
  }
907199
public void redirect(String path) throws IOException
    {
        //response.setHeader("Location", path.charAt(0)=='/' ? path : "/"+path);
        response.sendRedirect(path.charAt(0)=='/' ? path : "/"+path);
        output.close();
    }
848501
def move(self, path, raise_if_exists=False):
        
        self.rename(path, raise_if_exists=raise_if_exists)
460186
def rename_dont_move(self, path, dest):
        
        self.move(path, dest, raise_if_exists=True)
715610
private Path renameCompletedFile(Path file) throws IOException {
    String fileName = file.toString();
    String fileNameMinusSuffix = fileName.substring(0, fileName.indexOf(inprogress_suffix));
    String newName = new Path(fileNameMinusSuffix).getName();

    Path  newFile = new Path( archiveDirPath + Path.SEPARATOR + newName );
    LOG.info("Completed consuming file {}", fileNameMinusSuffix);
    if (!hdfs.rename(file, newFile) ) {
      throw new IOException("Rename failed for file: " + file);
    }
    LOG.debug("Renamed file {} to {} ", file, newFile);
    return newFile;
  }
94228
public void setDone(String oldName, String newName) throws IOException {
        Path oldPath = new Path(oldName);
        fs.rename(oldPath, new Path(newName));
    }
1334519
public boolean rename(Path src, Path dst) throws IOException {
    if (fs.isDirectory(src)) {
      return fs.rename(src, dst);
    } else {

      boolean value = fs.rename(src, dst);
      if (!value)
        return false;

      Path checkFile = getChecksumFile(src);
      if (fs.exists(checkFile)) { //try to rename checksum
        if (fs.isDirectory(dst)) {
          value = fs.rename(checkFile, dst);
        } else {
          value = fs.rename(checkFile, getChecksumFile(dst));
        }
      }

      return value;
    }
  }
1167082
def action_rename(self, courseid, taskid, path, new_path):
        
        # normalize
        path = path.strip()
        new_path = new_path.strip()
        if not path.startswith("/"):
            path = "/" + path
        if not new_path.startswith("/"):
            new_path = "/" + new_path

        old_path = self.verify_path(courseid, taskid, path)
        if old_path is None:
            return self.show_tab_file(courseid, taskid, _("Internal error"))

        wanted_path = self.verify_path(courseid, taskid, new_path, True)
        if wanted_path is None:
            return self.show_tab_file(courseid, taskid, _("Invalid new path"))

        try:
            self.task_factory.get_task_fs(courseid, taskid).move(old_path, wanted_path)
            return self.show_tab_file(courseid, taskid)
        except:
            return self.show_tab_file(courseid, taskid, _("An error occurred while moving the files"))
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
483696
public static void rename(String from, String to) {
        try {
            Files.move(Paths.get(from), Paths.get(to), StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException e) {
            log.error("Error renaming file", e);
        }
    }
655793
public static void delete(FileSystem fs, String name) throws IOException {
    Path dir = new Path(name);
    Path data = new Path(dir, DATA_FILE_NAME);
    Path index = new Path(dir, INDEX_FILE_NAME);

    fs.delete(data, true);
    fs.delete(index, true);
    fs.delete(dir, true);
  }
748583
def rename(self, paths, dst):
        ''' 
        '''
        if not isinstance(paths, list):
            raise InvalidInputException("Paths should be a list")
        if not paths:
            raise InvalidInputException("rename: no path given")
        if not dst:
            raise InvalidInputException("rename: no destination given")

        processor = lambda path, node, dst=dst: self._handle_rename(path, node, dst)
        for item in self._find_items(paths, processor, include_toplevel=True):
            if item:
                yield item