Skip to content

Instantly share code, notes, and snippets.

@homm
Created July 16, 2016 22:41
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 homm/5a576f99fda699b9cd680cf22e676bc8 to your computer and use it in GitHub Desktop.
Save homm/5a576f99fda699b9cd680cf22e676bc8 to your computer and use it in GitHub Desktop.
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