First, there are several sub-folders in the folder, and there are several pictures in the sub-folder, according to the requirements to copy the pictures in the sub-folder to the new folder, and rename these pictures. Copy label. PNG images from subfiles named rGB_0001_json in train folder to mask folder and rename it rGB_0001.png. import os import shutil path = ‘c:/Users/Administrator/Desktop/train’ new_path = ‘c:/Users/Administrator/Desktop/mask’ count = os.listdir(path) for j in range(1,len(count)+1): for root, dirs, files in os.walk(path): if len(dirs) == 0: for i in range(len(files)): print(“i=”,i) if files.find(‘label.png’)! = 1: shutil.copy(os.path.join(path+’/rgb_’+str(j).zfill(4)+’_json/’,files), Os.path. join(new_path,’rgb_’+ STR (j).zfill(4)+’.png’)) where path is the path of the original folder and new_path is the path of the new folder. Shutil. copy shutil.copy() shutil.copy(source,destination) source/destination is a string of paths, where destination is: shutil.copy shutil.copy() shutil.copy(source,destination) (1) copy the source file to destination (2) copy the source file to destination (3) If the folder does not exist, OSError invalid argument = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = C: / Users/Administrator/Desktop/mask. — — — — — — — — — — — — — — — — — — — — – the author: scampering lambs source: CSDN, blog.csdn.net/yql_6175402… Copyright notice: This article is the blogger’s original article, reprint please attach the blog link!

For more free technical information: annalin1203