If base.ext exists, append _01, _02, ...
(dest_dir: Path, base: str, ext: str)
| 90 | |
| 91 | |
| 92 | def unique_name(dest_dir: Path, base: str, ext: str) -> Path: |
| 93 | """ |
| 94 | If base.ext exists, append _01, _02, ... |
| 95 | """ |
| 96 | cand = dest_dir / f"{base}{ext}" |
| 97 | if not cand.exists(): |
| 98 | return cand |
| 99 | i = 1 |
| 100 | while True: |
| 101 | cand = dest_dir / f"{base}_{i:02d}{ext}" |
| 102 | if not cand.exists(): |
| 103 | return cand |
| 104 | i += 1 |
| 105 | |
| 106 | |
| 107 | @dataclass |