import os for root, dirs, files in os.walk("."): for f in files: base, ext = os.path.splitext(f) if ext[1:].lower() in ("png", "jpg"): src = os.path.join(root, f) target = os.path.join(root, base + "-320x.webp") Command(f"{target}", f"{src}", action="convert -resize 320x $SOURCE $TARGET") Command("staff.html", "staff.md", action="pandoc --standalone $SOURCE -o $TARGET")