SHARE
TWEET

pathlib simple iterdir with regex

DeaD_EyE Apr 4th, 2019 (edited) 64 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
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top