mirror of
https://github.com/onyx-and-iris/grokking-algorithms.git
synced 2024-11-15 17:30:52 +00:00
32 lines
699 B
Python
32 lines
699 B
Python
import logging
|
|
from collections import deque
|
|
from pathlib import Path
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
EXT = ".rb"
|
|
|
|
scripts_path = Path.home() / "scripts"
|
|
|
|
|
|
def files_with_extension(start_directory):
|
|
queue = deque()
|
|
queue.append(start_directory)
|
|
|
|
while queue:
|
|
items = queue.popleft()
|
|
|
|
for item in items.glob("*"):
|
|
# if it is a file and has extension EXT then print
|
|
if item.is_file():
|
|
if item.suffix == EXT:
|
|
print(item)
|
|
|
|
# otherwise append directory to the queue
|
|
else:
|
|
queue.append(item)
|
|
|
|
|
|
files_with_extension(scripts_path)
|