From d1ac4594e4f20ea139566e43ace5582bc7dd102a Mon Sep 17 00:00:00 2001 From: dqy <1016751306@qq.com> Date: Mon, 3 Jun 2024 16:29:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8rglob=E6=89=AB?= =?UTF-8?q?=E6=8F=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- detection/__main__.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/detection/__main__.py b/detection/__main__.py index 24f8703..9881eb5 100644 --- a/detection/__main__.py +++ b/detection/__main__.py @@ -10,6 +10,7 @@ from .utils import * import sys from colorama import init, Fore, Style from tqdm import tqdm +from pathlib import Path PYCDC_FLAG = True PYCDC_ADDR_FLAG = True @@ -362,19 +363,18 @@ def process_path( ): results = {"high": [], "medium": [], "low": [], "none": []} if os.path.isdir(path): - # 获取所有文件 - all_files = [] - for root, dirs, files in os.walk(path): - for file in files: - file_extension = os.path.splitext(file)[1] - if file_extension in SUPPORTED_EXTENSIONS: - file_path = os.path.join(root, file) - all_files.append(file_path) + # 使用rglob获取所有文件 + all_files = [ + file_path + for file_path in Path(path).rglob("*") + if file_path.suffix in SUPPORTED_EXTENSIONS + ] + # 扫描动画 for file_path in tqdm(all_files, desc="Scanning files", unit="file"): - file_extension = os.path.splitext(file_path)[1] + file_extension = file_path.suffix file_results = checkModeAndDetect( - mode, file_path, file_extension, pycdc_addr + mode, str(file_path), file_extension, pycdc_addr ) if file_results is not None: for key in file_results: