Created
March 17, 2022 17:29
-
-
Save shollingsworth/aeed7fcc6f5c2f68d390a3cd62492e53 to your computer and use it in GitHub Desktop.
iterate over json files using a recursive function
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
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| """Globbing.""" | |
| from pathlib import Path | |
| def _iterfiles(path:Path): | |
| for i in path.iterdir(): | |
| if i.is_dir(): | |
| yield from _iterfiles(i) | |
| else: | |
| if i.suffix == '.json': | |
| yield i | |
| def main(): | |
| """Run main function.""" | |
| for i in _iterfiles(Path('~').expanduser()): | |
| print(i) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment