Skip to content

Instantly share code, notes, and snippets.

@gyli
Created February 19, 2023 01:39
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 gyli/fea9d28d85ea76f24453092e53dbbd38 to your computer and use it in GitHub Desktop.
Save gyli/fea9d28d85ea76f24453092e53dbbd38 to your computer and use it in GitHub Desktop.
Scan dir recursively and efficiently with os.scandir
import os
def scantree(path):
"""Recursively yield DirEntry objects for given directory."""
for entry in os.scandir(path):
if entry.is_dir(follow_symlinks=True):
yield from scantree(entry.path)
else:
yield entry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment