Advertisement
DeaD_EyE

pathlib simple iterdir with regex

Apr 4th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.26 KB | None | 0 0
  1. from pathlib import Path
  2. import re
  3.  
  4. PATTERN = re.compile(r'^\d{4}-\d{2}-\d{2}')
  5. WORKDIR = Path.home()
  6. MEDIA = WORKDIR / 'Downloads'
  7.  
  8. for file in MEDIA.iterdir():
  9.     if file.is_file() and PATTERN.search(str(file.name)):
  10.         print(file.name, 'found')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement