DeaD_EyE

pathlib simple iterdir with regex

Apr 4th, 2019
108
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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')
RAW Paste Data