diff --git a/src/sp2xr/helpers.py b/src/sp2xr/helpers.py index 52867ad..c44c76f 100644 --- a/src/sp2xr/helpers.py +++ b/src/sp2xr/helpers.py @@ -1,7 +1,7 @@ import os import re from pathlib import Path -from typing import Optional +from typing import Optional, List def find_matching_hk_file(pbp_path: str) -> Optional[str]: @@ -28,3 +28,23 @@ def extract_base_filename(file_path: str) -> str: if len(parts) >= 2: return f"{parts[-2]}_{parts[-1]}" return Path(file_path).stem + + +def find_files(directory: str, pattern: str) -> List[str]: + """ + Recursively find all files in `directory` containing `pattern`. + """ + matches = [] + for root, _, files in os.walk(directory): + for f in files: + if pattern in f: + matches.append(str(Path(root) / f)) + return sorted(matches) + + +def chunks(lst: List[str], n: int): + """ + Yield successive `n`-sized chunks from list `lst`. + """ + for i in range(0, len(lst), n): + yield lst[i : i + n]