# 创建一些文件
def createFile(dst_path,name,suffix):
num = 0
for i in range(30):
file = open(os.path.join(dst_path, name + "_" + str(num) + suffix),'w')
file.close()
num += 1
# 判断origin目录中的.txt去除后缀后是否在dst中找到去除后缀加上一个新的jpg后缀,找不到就把origin目录中这个.txt删除
def judgeAIsOrNotInDirB(origin_path, dst_path):
txt_list = glob2.glob(origin_path + "/*.txt")
for txt in tqdm(txt_list):
jpg_path = txt.replace('.txt', '.jpg')
jpg_name = os.path.split(jpg_path)[1]
path_file = os.path.join(dst_path, jpg_name)
if not os.path.exists(path_file):
print("txt:" + txt)
os.remove(txt)
origin_path = "D:/data/origin"
dst_path = "D:/data/dst"
createFile("D:/data/origin", "Test", ".txt")
createFile("D:/data/origin", "Test", ".jpg")
judgeAIsOrNotInDirB(origin_path, dst_path)
创建文件
判断后: