import os from PIL import Image file_path = '/home/zbz5349/WorkSpace/aigeeks/ml-mgie/single_50' src_img_path = '/home/zbz5349/WorkSpace/aigeeks/ml-mgie/single_result' save_src_path = '/home/zbz5349/WorkSpace/aigeeks/ml-mgie/single2_50' os.makedirs(save_src_path,exist_ok=True) idx = 0 for file in os.listdir(file_path): idx = idx + 1 print(file[2:]) x = '2' + file[1:] img_path = os.path.join(src_img_path, x) img = Image.open(img_path) save_img_path = os.path.join(save_src_path,x) img.save(save_img_path)