乱序批量精确修改文件名



# --** coding="UTF-8" **--


import os

# 导入包含字典的文件 
# import dirt


def accurate_rename(file_path, name_dirt):
    """
    :param file_path: input your file path
    :param name_dirt: import file name dictionary
    :return:none;
    """

    fileList = os.listdir(file_path)

    count = 0

    try:
        for i in fileList:
            old_name = file_path + i

            new_name = file_path + name_dirt[i]

            os.rename(old_name, new_name)

            print(i + "已改为" + name_dirt[i])

            count += 1

    except Exception as result:
        print(result)


    print("[%d]个文件完成重命名" % count)


if __name__ == '__main__':
    accurate_rename("../dirtpath/", name_dirt)

 

 
posted @ 2019-08-20 23:02  Jrri  阅读(335)  评论(0编辑  收藏  举报