Last active
July 14, 2016 00:38
-
-
Save dmyersturnbull/aae128f884bb6e5517cd13f5d23153a0 to your computer and use it in GitHub Desktop.
List the full path of every meaningful file in a directory recursively.
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 | |
| from typing import Iterator | |
| def is_proper_file(path: str) -> bool: | |
| name = os.path.split(path)[1] | |
| return len(name) > 0 and name[0] not in {'.', '~', '_'} | |
| def scantree(path: str, follow_symlinks: bool=False) -> Iterator[str]: | |
| """List the full path of every file not beginning with '.', '~', or '_' in a directory, recursively.""" | |
| for entry in os.scandir(path): | |
| if entry.is_dir(follow_symlinks=follow_symlinks): | |
| yield from scantree(entry.path) | |
| elif is_proper_file(entry.path): | |
| yield entry.path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment