使用python将多级子目录下的图片复制到一个文件夹下,并将子目录中的图片名字更改
import os
import shutil
determination = 'D:/xx/xx'
if not os.path.exists(determination):
os.makedirs(determination)
path = 'D:/xx/xx/xx'
first_dir = os.listdir(path)
for first in first_dir:
dir = path + '/' + str(first)
second_dir = os.listdir(dir)
for second in second_dir:
source = dir + '/' + str(second)
imgs = os.listdir(source)
for img in imgs:
source_img = source + '/' + str(img)
deter = determination + '/' + str(first) + '_' + str(second) + '_' + str(img)
shutil.copyfile(source_img, deter)