from pathlib import Path
import csv

root = Path('rename_demo')
files = sorted(p for p in root.iterdir() if p.is_file() and not p.is_symlink() and p.suffix.lower() in {'.jpg', '.jpeg', '.png'})
plan = [(p, root / f'photo_{i:03d}{p.suffix.lower()}') for i, p in enumerate(files, 1)]
for old, new in plan:
    if new.exists() and new != old:
        raise FileExistsError(f'名称冲突: {new}')
with Path('rename-plan.csv').open('x', encoding='utf-8-sig', newline='') as stream:
    writer = csv.writer(stream)
    writer.writerow(['原路径', '新路径'])
    for old, new in plan:
        writer.writerow([str(old), str(new)])
        print(old.name, '->', new.name)
print('仅生成清单，未执行重命名')
