import os import shutil import time start_time = time.time() # 需要被复制的文件夹 old_path = r'C:old_dir' new_path = r'C: ew_dir' all_list = os.listdir(old_path) for i in all_list: # print(os.path.join(old_path,i)) for j in os.listdir(os.path.join(old_path,i)): print(j) if j=='label.png': name= i.split('_json')[0] # name = name.replace('.','') old_name = old_path + '\' + i + '\' + j new_name = new_path + '\' + name + ".png" print(new_name) shutil.copyfile(old_name, new_name) # print(len(all_list)) # print(all_list) end_time = time.time() print(end_time-start_time,'秒')