Skip to content

Instantly share code, notes, and snippets.

@phretor
Created November 30, 2016 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phretor/780d718b0c826d48eccc03f5e2cbff45 to your computer and use it in GitHub Desktop.
Save phretor/780d718b0c826d48eccc03f5e2cbff45 to your computer and use it in GitHub Desktop.
Python pathlib2-based recursive directory iterator with depth limits
def _dig(p, max_depth, depth=1):
for sp in p.iterdir():
if sp.is_file():
yield sp
elif sp.is_dir() and depth <= max_depth:
depth += 1
for ssp in _dig(sp, max_depth, depth):
yield ssp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment