from pathlib import Path
if __name__ == '__main__':
img_files = [
Path(r"Clothes"),
Path(r"train_bn")]
txt_files = [
Path(r"Clothes"),
Path(r"train_bn")]
result_png_list = r"val.txt"
write_png = open(result_png_list, "w", encoding="utf-8")
for img_file, txt_file in zip(img_files, txt_files):
for img_pth, txt_pth in list(zip(img_file.glob("*.jpg"), txt_file.glob("*.txt"))):
txt_pth = str(txt_file / img_pth.stem) + ".txt"
if img_pth.is_file() and Path(txt_pth).is_file():
print(f"{str(img_pth)}")
write_png.write(str(img_pth) + "\n")
else:
print(f"文件:{str(img_pth.stem)} 有一个不存在!")
write_png.close()