from pathlib import Path img = Path("images") for src in img.glob("*.png"): # print (src) target = img / f"{src.stem}-320x.webp" # print (target) Command(f"{target}", f"{src}", action="convert -resize 320x $SOURCE $TARGET") # Command(, f"{src}")