Created
February 19, 2023 01:39
-
-
Save gyli/fea9d28d85ea76f24453092e53dbbd38 to your computer and use it in GitHub Desktop.
Scan dir recursively and efficiently with os.scandir
This file contains hidden or 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
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