def rename_file(filepath, new_name, overwrite=True, delete=True):
    _dir, _file = os.path.split(filepath)
    _ext = os.path.splitext(_file)[1]
    _new_file_name = new_name + _ext
    _new_path = os.path.join(_dir, _new_file_name)
    print 'renaming file...'
    # folder
    if os.path.isdir(filepath):
        if os.path.exists(_new_path):
            if overwrite:
                shutil.rmtree(_new_path)
        print '\tsaving %s as %s...' % (filepath, _new_path)
        shutil.copytree(filepath, _new_path)
        if delete:
            print '\tdeleting %s...' % filepath
            shutil.rmtree(filepath)
    # file
    else:
        print '\tsaving %s as %s...' % (filepath, _new_path)
        shutil.copy(filepath, _new_path)
        if delete:
            print '\tdeleting %s...' % filepath
            os.remove(filepath)
    print '...done.\n'

# def prepend_zeros(number, length):
#     """Add padding with zeros before number for sorting."""
#     _number = str(number)
#     _padding = length - len(_number)
#     return '%s%s' % ('0' * _padding, _number)
Rename a file or folder, and save it with the new name.
dataset/ETHPy150Open gferreira/hTools2/Lib/hTools2/modules/fileutils.py/rename_file