Created
July 16, 2016 22:41
-
-
Save homm/5a576f99fda699b9cd680cf22e676bc8 to your computer and use it in GitHub Desktop.
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
from scandir import scandir | |
def recursive_scandir(dir): | |
stack = [] | |
it = scandir(dir) | |
while it or stack: | |
it = it or stack.pop() | |
try: | |
item = next(it) | |
except StopIteration: | |
it = None | |
continue | |
yield item | |
if item.is_dir(): | |
stack.append(it) | |
it = scandir(item.path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment