为了解决在原图文件夹中寻找特定名称的图片所对应的原图
import shutil
import os
def copy_img():
'''
复制、重命名、粘贴文件
:return:
'''
ori_img_name=r''
target=r''
imgs=os.listdir(target)
path = r''
os.mkdir(path)
for i in imgs:
new_obj_name = i
print(i)
shutil.copy(ori_img_name+'/'+new_obj_name,path+'/'+new_obj_name)
if __name__ == '__main__':
copy_img()
import shutil
import os
def copy_img():
'''
复制、重命名、粘贴文件
:return:
'''
ori_img_name = r''
target = r''
imgs = os.listdir(target)
a=[]
n=0
path = r''
depth_name=os.listdir(ori_img_name)
for i in imgs:
name1=i.split('.')[0]
new_obj_name = name1+'.png'
print(i)
if new_obj_name in depth_name:
shutil.copy(ori_img_name + '/' + new_obj_name, path + '/' + new_obj_name)
else:
a.append(new_obj_name)
n+=1
print('a :',a)
print('num:',n)
if __name__ == '__main__':
copy_img()