From 0a7dbdc54deca7cd564f2e6fc3b81f462e20a70c Mon Sep 17 00:00:00 2001 From: Lan <ldam@passcal.nmt.edu> Date: Wed, 10 May 2023 10:24:05 -0600 Subject: [PATCH] add get_total_riles to controller/util.py --- sohstationviewer/controller/util.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/sohstationviewer/controller/util.py b/sohstationviewer/controller/util.py index 85c8203f7..c309427c4 100644 --- a/sohstationviewer/controller/util.py +++ b/sohstationviewer/controller/util.py @@ -24,7 +24,6 @@ def validate_file(path2file: Union[str, Path], file_name: str): :param file_name: name of the file :return: True if pass checking, False if not. """ - if file_name.startswith('.'): # skip info file return False @@ -49,6 +48,25 @@ def validate_dir(path: str): raise Exception(f"Skip info folder: {path}") +def get_total_files(list_of_dir: Path) -> int: + """ + Get total number of valid files in valid directories from the list_of_dir + :param list_of_dir: + :return total: total number of valid files + """ + total = 0 + for folder in list_of_dir: + for path, _, files in os.walk(folder): + try: + validate_dir(path) + except Exception: + continue + total += len([f for f in files + if validate_file(Path(path).joinpath(f), f)]) + + return total + + @QtCore.Slot() def display_tracking_info(tracking_box: QTextBrowser, text: str, type: LogType = LogType.INFO): -- GitLab