SHOW:
|
|
- or go back to the newest paste.
| 1 | import re | |
| 2 | from pathlib import * | |
| 3 | ||
| 4 | directory = Path("/test")
| |
| 5 | pattern = r"^file([0-9]+).log$" | |
| 6 | ||
| 7 | next_log_num = 1 | |
| 8 | ||
| 9 | for f in directory.iterdir(): | |
| 10 | m = re.match(pattern, f.name) | |
| 11 | ||
| 12 | if m: | |
| 13 | file_num = int(m.group(1)) | |
| 14 | ||
| 15 | if file_num >= next_log_num: | |
| 16 | next_log_num = file_num + 1 | |
| 17 | ||
| 18 | print(next_log_num) |