Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- from pathlib import *
- directory = Path("/test")
- pattern = r"^file([0-9]+).log$"
- next_log_num = 1
- for f in directory.iterdir():
- m = re.match(pattern, f.name)
- if m:
- file_num = int(m.group(1))
- if file_num >= next_log_num:
- next_log_num = file_num + 1
- print(next_log_num)
Add Comment
Please, Sign In to add comment