thorpedosg

Untitled

Jul 24th, 2018
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
Add Comment
Please, Sign In to add comment