Created
November 30, 2016 11:46
-
-
Save phretor/780d718b0c826d48eccc03f5e2cbff45 to your computer and use it in GitHub Desktop.
Python pathlib2-based recursive directory iterator with depth limits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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