From c42ed9336b2b72508e62e629705e26829b18e3a3 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Tue, 6 Jun 2023 08:06:38 +0800 Subject: [PATCH] fix --- app/utils/system.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/utils/system.py b/app/utils/system.py index 519f298a..1d39d210 100644 --- a/app/utils/system.py +++ b/app/utils/system.py @@ -1,5 +1,6 @@ import os import platform +import re import shutil from pathlib import Path @@ -83,3 +84,15 @@ class SystemUtils: except Exception as err: print(str(err)) return -1, str(err) + + @staticmethod + def list_files_with_extensions(directory: Path, extensions: list) -> list: + files = [] + pattern = r".*\.(" + "|".join(extensions) + ")$" + + # 遍历目录及子目录 + for path in directory.glob('**/*'): + if path.is_file() and re.match(pattern, str(path), re.IGNORECASE): + files.append(path) + + return files