| from pathlib import Path | |
| # Folder containing your files | |
| data_dir = Path("data/animations") | |
| # List all .webp files sorted | |
| files = sorted(data_dir.glob("*.webp")) | |
| import re | |
| pattern = re.compile(r"sample-\d{3}\.webp$") | |
| for i, f in enumerate(files): | |
| new_name = f"sample-{i:03d}.webp" # e.g. sample-000.webp | |
| if pattern.fullmatch(f.name): | |
| # Already correctly named, skip | |
| continue | |
| new_path = f.with_name(new_name) | |
| print(f"{f.name} → {new_name}") | |
| f.rename(new_path) |