Skip to content

Instantly share code, notes, and snippets.

Created Nov 30, 2016
What would you like to do?
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