Skip to content

Commit

Permalink
utils:functions - add find_files function to generate a recursive lis…
Browse files Browse the repository at this point in the history
…t of files
  • Loading branch information
MatteoCampinoti94 committed Nov 3, 2023
1 parent 744ca41 commit b4985f2
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions acacore/utils/functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from hashlib import sha256
from pathlib import Path
from typing import Callable
from typing import Generator
from typing import Optional
from typing import TypeVar

Expand Down Expand Up @@ -36,6 +37,17 @@ def rm_tree(path: Path):
path.rmdir()


def find_files(*root: Path, exclude: list[Path] = None) -> Generator[Path, None, None]:
exclude = exclude or []
for f in root:
if f in exclude:
continue
elif f.is_file():
yield f
elif f.is_dir():
yield from find_files(*f.iterdir(), exclude=exclude)


def file_checksum(path: Path) -> str:
file_hash = sha256()
with path.open("rb") as f:
Expand Down

0 comments on commit b4985f2

Please sign in to comment.