# -*- coding: utf-8 -*- """ @author: Mr_zhang @software: PyCharm @file: renamefile.py @time: 2021/8/18 下午2:55 """ import time import random # import os # # BASE_DIR = os.path.abspath(os.path.dirname(__file__)) # demo_txt = os.path.join(BASE_DIR, 'demo.txt') # demo_json = os.path.join(BASE_DIR, 'demo.json') # os.rename(demo_txt, 'demo.txt') # os.replace(demo_txt, demo_json) start_time = time.time() old_file_list = [] new_file_list = [] for i in range(10000): old_file_list.append("14-20210818-%s-软件工程-本科.jpg" % i) new_file_list.append("20210818-%s.jpg" % i) random.shuffle(old_file_list) random.shuffle(new_file_list) for new_file in new_file_list: id_card = new_file.split(".")[0] for old_file in old_file_list: if id_card in old_file: new_file_list[new_file_list.index(new_file)] = old_file break print(old_file_list) print(new_file_list) print(time.time() - start_time)