import os # 读取真实标签文件列表,不含文件后缀 path_A = './ground-truth' set_A = set (i.split('.')[0] for i in os.listdir(path_A)) print(path_A ,"files:", len(set_A)) # 读取检测结果文件列表,不含文件后缀 path_B = './detection-results' set_B = set (i.split('.')[0] for i in os.listdir(path_B)) print(path_B, "files:", len(set_B)) # 删除两个文件夹中不同的文件 for i in set_A - set_B: os.remove(os.path.join(path_A, i + '.xml')) for i in set_B - set_A: os.remove(os.path.join(path_B, i + '.txt'))
参考:
https://blog.csdn.net/weixin_62273462/article/details/125930482
https://blog.csdn.net/hxc0520/article/details/121394790
标签:文件,set,删除,python,文件夹,csdn,path,os From: https://www.cnblogs.com/d442130165/p/16590709.html