Move the given file or directory to the same name, with a backup suffix.
  If backup_suffix not supplied, move it to the extension ".bak".
  NB: If backup_suffix is supplied and is None, don't do anything.
491305
def move_to_backup(path, backup_suffix=BACKUP_SUFFIX):
  
  if backup_suffix and os.path.exists(path):
    backup_path = path + backup_suffix
    # Some messy corner cases need to be handled for existing backups.
    # TODO: Note if this is a directory, and we do this twice at once, there is a potential race
    # that could leave one backup inside the other.
    if os.path.islink(backup_path):
      os.unlink(backup_path)
    elif os.path.isdir(backup_path):
      shutil.rmtree(backup_path)
    shutil.move(path, backup_path)
604797
def file_name_increase(file_name, file_location):
    
    add_one = 1
    file_name_temp = file_name
    while verify_file_exists(file_name_temp, file_location):
        try:
            name, file_extension = file_name.split('.')
            file_name_temp = '%s-%i.%s' % (name, add_one, file_extension)
        except Exception as e:
            LOGGER.critical('Function file_name_increase Error {error} ignoring any errors'.format(error=e))
            name = file_name
            file_name_temp = '%s-%i' % (name, add_one)
        add_one += 1
    file_name = file_name_temp
    return file_name
694111
function move(oldPath, newPath) {
  if (toDel[oldPath] || !fileExists(oldPath)) {
    log('Error: no file to move: ', 'red', oldPath);
    throw new Error('No file to move');
  }

  if (fileExists(newPath)) {
    log('Error: target file already exists: ', 'red', newPath);
    throw new Error('Target file already exists');
  }
  if (fileLines[oldPath]) {
    fileLines[newPath] = fileLines[oldPath];
    delete fileLines[oldPath];
  }

  // if (asts[oldPath]) {
  //   asts[newPath] = asts[oldPath];
  //   delete asts[oldPath];
  // }

  if (toSave[oldPath]) {
    toSave[newPath] = true;
    delete toSave[oldPath];
  }

  if (toDel[oldPath]) {
    delete toDel[oldPath];
  }
  // if the file has already been moved
  oldPath = _.findKey(mvs, s => s === oldPath) || oldPath;
  mvs[oldPath] = newPath;
}
134072
def add_suffix(path, suffix=""):
    """"""
    return join(dirname(path), basename(path, ext=False) + suffix + extname(path))
349599
def archive_basename(filename):
    ''''''
    for archive in archive_formats:
        if filename.endswith(archive_formats[archive]['suffix']):
            return filename.rstrip('.' + archive_formats[archive]['suffix'])
    return False
1204747
def do_action(self, target, dry_run=False):
        
        original_path = os.path.dirname(target)
        original_filename, original_extension = os.path.splitext(os.path.basename(target))

        new_filename = re.sub(self.match, self.replace_with, original_filename) + original_extension
        destination = os.path.join(original_path, new_filename)

        if dry_run is True:
            self.logger.debug("Dry run: Skipping rename {0} to {1}".format(target, new_filename))
            return target
        else:
            self.logger.debug("Renaming {0} to {1}".format(original_filename + original_extension,
                                                           new_filename + original_extension))

            if not os.path.exists(destination):
                try:
                    shutil.move(target, destination)
                except IOError:
                    self.logger.error("Error renaming file {0} to {1}".format(target, new_filename))
                    raise IOError
            else:
                self.logger.error("Destination file already exists: {0}".format(new_filename))
                raise IOError

        return destination
814736
def step_an_empty_file_named_filename(context, filename):
    
    assert not os.path.isabs(filename)
    command_util.ensure_workdir_exists(context)
    filename2 = os.path.join(context.workdir, filename)
    pathutil.create_textfile_with_contents(filename2, "")
1125445
def _auto_complete_filename(self, location):
        
        path = formatted(location, self)
        if path:
            if os.path.isdir(path):
                filename = formatted(self.basename, self)
                if not filename:
                    return None
                path = os.path.join(path, filename)
            if path and ensure_folder(path, fatal=False, logger=LOG.debug, dryrun=False) >= 0:
                return path
930486
def filename(self, prefix='', suffix='', extension='.py'):
        """"""
        return BASE_NAME.format(prefix, self.num, suffix, extension)
1050920
def move(srcpath, dstpath, overwrite=True):
    """"""
    # TODO: (JRR@201612230924) Consider adding smarter checks to prevent files ending up with directory names; e.g. if dstpath directory does not exist.
    if not op.exists(srcpath):
        return False
    if srcpath == dstpath:
        return True
    if op.isfile(srcpath) and op.isdir(dstpath):
        verfunc = op.isfile
        verpath = op.join(dstpath, op.basename(srcpath))
    elif op.isfile(srcpath):
        verfunc = op.isfile
        verpath = dstpath
        makedirs(dstpath)
    elif op.isdir(srcpath) and op.isdir(dstpath):
        verfunc = op.isdir
        verpath = op.join(dstpath, op.basename(srcpath))
    elif op.isdir(srcpath):
        verfunc = op.isdir
        verpath = dstpath
    else:
        return False
    if op.isfile(verpath):
        if not overwrite:
            return False
        else:
            # On Windows, filename case is ignored so the following check will
            # prevent unintentionally deleting the srcpath before moving.
            if "nt" == os.name and srcpath.lower() == dstpath.lower():
                pass
            elif not delete(verpath):
                return False
    try:
        shutil.move(srcpath, dstpath)
    except:
        return False
    return verfunc(verpath)
68106
def prefix(filename):
    '''  '''
    return os.path.split(re.sub(_afni_suffix_regex,"",str(filename)))[1]
323282
def __filename(self, id):
        """"""
        suffix = self.fnsuffix()
        filename = "%s-%s.%s" % (self.fnprefix, id, suffix)
        return os.path.join(self.location, filename)
1170964
public static void backup(final String filename) throws IOException {
        final File dest = createFile(filename);
        if (dest.exists()) {
            final File backupFile = generateBackupFilename(filename);
            LOGGER.debug("backing up file from " + filename + " to "
                    + backupFile.getName());
            if (!dest.renameTo(backupFile)) {
                throw new IOException("Could not rename file from "
                        + dest.getName() + " to " + backupFile.getName());
            }
        }
    }
890325
def _fileMoved(self, oldPathName: str, file: 'File'):
        

        self._files.pop(oldPathName)
        self._files[file.pathName] = file
1073318
def _add_suffix(file_path, suffix, sep='_', ext=None):
    """"""
    # Split file_path on last '.' to separate file_name and file_extension
    split = os.path.basename(file_path).rsplit('.', 1)

    # Use original file_extension if None is given
    ext = split[1] if not ext else ext.strip('.')

    # Rebuild new file_path with suffix
    return os.path.join(os.path.dirname(file_path), split[0] + sep + suffix + '.' + ext)
1275833
def get_backup_path():
    
    dirname, filename = path.split(path.splitext(config().todotxt())[0])
    filename = '.' + filename + '.bak'

    return path.join(dirname, filename)
1041901
def add_suffix(filename, suffix):
        
        path = filename.split("/")
        parts = path[-1].split(".")
        i = max(len(parts) - 2, 0)
        parts[i] = parts[i] + suffix
        path[-1] = ".".join(parts)
        return "/".join(path)