1.从txt中读取每一行的文件夹名称
2.找到图像路径、xml路径下该文件夹,并直接复制整个文件夹到新的文件夹中
#导入shutil模块和os模块
import shutil,os
imgPath = "D:\\HeadModel\\img"
xmlPath = "D:\\HeadModel\\xml"
newImgPath = "D:\\HeadModel2\\img"
newXmlPath = "D:\\HeadModel2\\xml"
with open("test.txt", "r") as f:
for line in f.readlines(): #依次读取txt每一行数据,readlines会读到换行符
line = line.strip('\n') #去掉列表中每一个元素的换行符
#line = line[:-1] #去掉换行符,也可以不去
print(line) #line: 文件夹名
shutil.copytree(imgPath+line,newImgPath+line)#复制整个文件夹
shutil.copytree(xmlPath+line,newXmlPath+line)
print(newImgPath+line)
print(newXmlPath+line)