Rename files in bulk with Python

A pathlib loop beats fighting with the shell's rename command every time.

SNP 114 #942 Filed python

Add a prefix, pad numbers, swap spaces for dashes, whatever you need:

python
from pathlib import Path

folder = Path(".")

for path in sorted(folder.glob("*.png")):
    new_name = path.stem.lower().replace(" ", "-") + path.suffix
    if new_name != path.name:
        print(f"{path.name} -> {new_name}")
        path.rename(path.with_name(new_name))

Comment out the rename line for a dry run first. glob("**/*.png") goes into subfolders too.

The Buffy episode script is the same idea with a very specific ordering rule.