改进 SystemUtils.list_files 遍历目录对特殊字符的兼容性(如'[]')

This commit is contained in:
wdmcheng
2024-10-30 17:31:01 +08:00
parent b4e233678d
commit d863a7cb7f

View File

@@ -193,8 +193,8 @@ class SystemUtils:
pattern = r".*"
# 遍历目录及子目录
for matched_glob in glob(str(directory / '**'), recursive=recursive, include_hidden=True):
path = Path(matched_glob)
for matched_glob in glob('**', root_dir=directory, recursive=recursive, include_hidden=True):
path = directory.joinpath(matched_glob)
if path.is_file() \
and re.match(pattern, path.name, re.IGNORECASE) \
and path.stat().st_size >= min_filesize * 1024 * 1024:
@@ -229,8 +229,8 @@ class SystemUtils:
pattern = r".*(" + "|".join(extensions) + ")$"
# 遍历目录及子目录
for matched_glob in glob(str(directory / '**'), recursive=recursive, include_hidden=True):
path = Path(matched_glob)
for matched_glob in glob('**', root_dir=directory, recursive=recursive, include_hidden=True):
path = directory.joinpath(matched_glob)
if path.is_file() \
and re.match(pattern, path.name, re.IGNORECASE) \
and path.stat().st_size >= min_filesize * 1024 * 1024: