File size: 500 Bytes
f3573cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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)