遍历文件夹,将所需要的文本复制到人一个文件夹
# -*- coding:utf-8 -*-import os
import os.path
import re
importshutil
label_dir="D:\\工作任务\\wzg\\datasetTraffic\\Annotations"#已知文件
data_base_dir = open("D:\\工作任务\\wzg\\person1.txt","r")#给定的需要查找的txt
annotion_dir="D:\\工作任务\\wzg\\datasetTraffic\\ren"#得到的结果
lab = os.listdir(label_dir)
s = []
for i in data_base_dir:
b = i.strip()
for fileNum in lab:
if not os.path.isdir(fileNum):
a = fileNum
if(b ==a):
print(a)
#shutil.copy(a ,annotion_dir)
for file in os.listdir(label_dir):
if os.path.isfile(label_dir +'/'+file):
if b in file:
shutil.copy(label_dir +'/'+file, annotion_dir +'/'+file)
页:
[1]