Skip to content

Instantly share code, notes, and snippets.

@liushapku
Created January 10, 2019 01:51
Show Gist options
  • Save liushapku/a79ba06fab6c843c02ab382585591882 to your computer and use it in GitHub Desktop.
Save liushapku/a79ba06fab6c843c02ab382585591882 to your computer and use it in GitHub Desktop.
python scan tree
import os
def scantree(*paths):
for path in paths:
if os.path.exists(path):
for entry in sorted(os.scandir(path), key=lambda x: x.name.lower()):
yield entry
if entry.is_dir(follow_symlinks=False):
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