mirror of
https://github.com/onyx-and-iris/grokking-algorithms.git
synced 2024-11-15 17:30:52 +00:00
add dirtrav
This commit is contained in:
parent
dfea7449d2
commit
4b8a8f006c
27
chapter7/dirtrav.py
Normal file
27
chapter7/dirtrav.py
Normal file
@ -0,0 +1,27 @@
|
||||
import logging
|
||||
from collections import deque
|
||||
from pathlib import Path
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
scripts_path = Path.home() / "scripts"
|
||||
|
||||
|
||||
def files_with_extension(ext):
|
||||
queue = deque()
|
||||
queue += scripts_path.glob("*")
|
||||
|
||||
while queue:
|
||||
item = queue.popleft()
|
||||
|
||||
# if it is a file and has extension ext then print
|
||||
if item.is_file() and item.suffix == ext:
|
||||
print(item)
|
||||
|
||||
# otherwise add directory items to the queue
|
||||
else:
|
||||
queue += item.glob("*")
|
||||
|
||||
|
||||
files_with_extension(".sh")
|
Loading…
Reference in New Issue
Block a user