做自己的数据集时,想要用python提取多个文件夹中名称为“C.jpg”的图片
放在新建文件夹里并且重命名
import os
import shutil
new_img_folder='G:\\pix2pix\\help\\New_image'
#遍历读取文件夹筛选符合标准的图片
dir_path='G:\pix2pix\help'
i=1
for root,dirs,files in os.walk(dir_path):
for file in files:
if file.count('C')==1:
img=file
shutil.copy(os.path.join(root,file),new_img_folder)
now_path=os.path.join(root,file)
A=os.path.basename(now_path)
B=str(i)
os.rename(A, B) #重命名,覆盖原先的名字
i=i+1
报错:
File "G:/pix2pix/help/untitled0.py", line 24, in <module>
os.rename(A, B) #重命名,覆盖原先的名字
FileNotFoundError: [WinError 2] 系统找不到指定的文件。: 'C.jpg' -> '1'