Rename a file if necessary.
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
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)
1308999
def rename_file(self, old_path, new_path):
        """"""
        if old_path not in self.paired_notebooks:
            try:
                # we do not know yet if this is a paired notebook (#190)
                # -> to get this information we open the notebook
                self.get(old_path, content=True)
            except Exception:
                pass

        if old_path not in self.paired_notebooks:
            super(TextFileContentsManager, self).rename_file(old_path, new_path)
            return

        fmt, formats = self.paired_notebooks.get(old_path)
        old_alt_paths = paired_paths(old_path, fmt, formats)

        # Is the new file name consistent with suffix?
        try:
            new_base = base_path(new_path, fmt)
        except Exception as err:
            raise HTTPError(400, str(err))

        for old_alt_path, alt_fmt in old_alt_paths:
            new_alt_path = full_path(new_base, alt_fmt)
            if self.exists(old_alt_path):
                super(TextFileContentsManager, self).rename_file(old_alt_path, new_alt_path)

        self.drop_paired_notebook(old_path)
        self.update_paired_notebooks(new_path, fmt, formats)
1215581
def rename(src, dst):
    '''
    
    '''
    src = os.path.expanduser(src)
    dst = os.path.expanduser(dst)

    if not os.path.isabs(src):
        raise SaltInvocationError('File path must be absolute.')

    try:
        os.rename(src, dst)
        return True
    except OSError:
        raise CommandExecutionError(
            'Could not rename \'{0}\' to \'{1}\''.format(src, dst)
        )
    return False
128080
def rename(oldPath, newPath, **kwargs):
    """"""
    import os
    return os.rename(oldPath, newPath, **kwargs)
233765
private void rename(File legacyFile, File newFile) throws IOException {
        if (!legacyFile.exists())   return;
        if (newFile.exists()) {
            Util.deleteFile(newFile);
        }
        if (!legacyFile.renameTo(newFile)) {
            LOGGER.warning("Failed to rename " + legacyFile + " to " + newFile);
        }
    }
356193
def overwrite_file_check(args, filename):
    """"""
    if not args['overwrite'] and os.path.exists(filename):
        # Confirm overwriting of the file, or modify filename
        if args['no_overwrite']:
            overwrite = False
        else:
            try:
                overwrite = confirm_input(input('Overwrite {0}? (yes/no): '
                                                .format(filename)))
            except (KeyboardInterrupt, EOFError):
                sys.exit()
        if not overwrite:
            new_filename = modify_filename_id(filename)
            while os.path.exists(new_filename):
                new_filename = modify_filename_id(new_filename)
            return new_filename
    return filename
848501
def move(self, path, raise_if_exists=False):
        
        self.rename(path, raise_if_exists=raise_if_exists)
654963
def cleanupFilename(self, name):
        """"""

        context = self.context
        id = ''
        name = name.replace('\\', '/')  # Fixup Windows filenames
        name = name.split('/')[-1]  # Throw away any path part.
        for c in name:
            if c.isalnum() or c in '._':
                id += c

        # Raise condition here, but not a lot we can do about that
        if context.check_id(id) is None and getattr(context, id, None) is None:
            return id

        # Now make the id unique
        count = 1
        while 1:
            if count == 1:
                sc = ''
            else:
                sc = str(count)
            newid = "copy{0:s}_of_{1:s}".format(sc, id)
            if context.check_id(newid) is None \
                    and getattr(context, newid, None) is None:
                return newid
            count += 1
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));
    }
  }
1310857
def __rename_file(self, source, target):
        

        for file_node in self.__script_editor.model.get_file_nodes(source, self.__script_editor.model.root_node):
            self.__script_editor.unregister_node_path(file_node)
            self.__rename_path(source, target)
            self.__script_editor.register_node_path(file_node)
            if self.__script_editor.model.is_authoring_node(file_node):
                self.__set_authoring_nodes(source, target)
            else:
                self.__script_editor.model.update_project_nodes(file_node.parent)
206135
def rename_with_prefix(self, prefix="", new_path=None, in_place=True, remove_desc=True):
        """"""
        # Temporary path #
        if new_path is None: prefixed = self.__class__(new_temp_path())
        else:                prefixed = self.__class__(new_path)
        # Generator #
        def prefixed_iterator():
            for i,read in enumerate(self):
                read.id = prefix + read.id
                if remove_desc: read.description = ""
                yield read
        # Do it #
        prefixed.write(prefixed_iterator())
        prefixed.close()
        # Replace it #
        if in_place:
            os.remove(self.path)
            shutil.move(prefixed, self.path)
        return prefixed
414043
def rename(self, new_path):
        
        rename_path = fix_raw_path(new_path)
        if is_folder(self.path):
            os.rename(self.path, rename_path)
        else:
            os.renames(self.path, rename_path)
98519
function rename(opts) {
    opts = opts || {};

    return through.obj(function (file, enc, cb) {
        file.path = opts.path;
        cb(null, file);
    });
}
684688
def name_replace(self, to_replace, replacement):
        """"""
        self.name = self.name.replace(to_replace, replacement)
1008701
function (oldPath, newPath, callback) {
	fs.rename( oldPath, newPath, function (err) {
		if (err) {
			callback( err );
		} else {
			callback( null, {
				filename: newPath.split( '/' ).pop(),
				filepath: newPath
			});
		}
	});
}
663258
def can_rename(self):
        # type: (LocalSourcePaths) -> bool
        
        return len(self._paths) == 1 and (
            self._paths[0].is_file() or
            blobxfer.models.upload.LocalSourcePath.is_stdin(
                str(self._paths[0]))
        )