# --** 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)