2022-03-14

How do I write file names to a new folder with an added prefix?

I'm trying to take a dir like ["cats.jpg", "dogs.jpg", "stars.jpg"] and resize them to 100x100 pixels and output the edited files into a new directory with the prefix "resized_" i.e ["resized_cats.jpg", "resized_dogs.jpg", "resized_stars.jpg"].

At the moment I'm getting the new directory but no files are being written to it.

batch =  glob.glob("files/batch/*.jpg")

for file in batch:
    img = cv2.imread(file,1)
    resize = cv2.resize(img, (100,100))
    
    if not os.path.exists("files/batchOut"):
        os.makedirs("files/batchOut")

    cv2.imwrite(f"files/batchOut/resized_{file}", resize)


No comments:

Post a Comment