Skip to content

Instantly share code, notes, and snippets.

@shollingsworth
Created March 17, 2022 17:29
Show Gist options
  • Save shollingsworth/aeed7fcc6f5c2f68d390a3cd62492e53 to your computer and use it in GitHub Desktop.
Save shollingsworth/aeed7fcc6f5c2f68d390a3cd62492e53 to your computer and use it in GitHub Desktop.
iterate over json files using a recursive function
#!/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