import cv2 import os lines = "" for file_name in os.listdir("thots_false"): path = "thots_false/" + file_name img = cv2.imread(path, cv2.IMREAD_GRAYSCALE) #cv2.imwrite(path, img) lines += path+ "\n" f = open("thots_false/bg.txt", "w") f.write(lines) f.close()