grokking-algorithms/chapter7/dfs_dirtrav.py

25 lines
543 B
Python
Raw Normal View History

2024-01-12 12:19:51 +00:00
import logging
from pathlib import Path
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
EXT = ".rb"
scripts_path = Path.home() / "scripts"
def files_with_extension(directory):
for item in directory.glob("*"):
2024-01-12 12:32:53 +00:00
# if item is a file and has extension EXT then print
2024-01-12 12:19:51 +00:00
if item.is_file():
if item.suffix == EXT:
print(item)
# otherwise pass directory to recursive call
else:
files_with_extension(item)
files_with_extension(scripts_path)