import os
def delet(path1,path2):
filelist = os.listdir(path1)
for item in filelist:
item_path1=path1+item
if item.endswith('.bmp'):
item_path2=path2+item[:-4]+'.xml'
if not os.path.exists(item_path2):
os.remove(item_path1)
print item_path1
if __name__ == '__main__':
inputimagePath = '/Documents/rgb/new0/'
inputlabel = 'Documents/rgb/label0/'
delet(inputimagePath,inputlabel)
类似的,删除将1txt中包含2txt的内容删除
import sys
result=[]
with open('Documents/ros/4_1_2/ImageSets/Main/trainval.txt','r') as f:
for line1 in f:
result.append(line1)
for train_txt in result:
a = 0
with open("/ocuments/ros/4_1_2/ImageSets/Main/test.txt", 'r') as f_w:
for line2 in f_w:
if train_txt in line2:
a=a+1
print 'dele'
break
if a == 0:
with open("Documents/ros/4_1_2/ImageSets/Main/new.txt", 'a+') as new:
new.write(train_txt)