mirror of
https://github.com/open-compass/opencompass.git
synced 2025-05-30 16:03:24 +08:00
22 lines
628 B
Python
22 lines
628 B
Python
import fnmatch
|
|
import os
|
|
from typing import List, Union
|
|
|
|
|
|
def match_files(path: str,
|
|
pattern: Union[str, List],
|
|
fuzzy: bool = False) -> List:
|
|
if isinstance(pattern, str):
|
|
pattern = [pattern]
|
|
if fuzzy:
|
|
pattern = [f'*{p}*' for p in pattern]
|
|
files_list = []
|
|
for root, _, files in os.walk(path):
|
|
for name in files:
|
|
for p in pattern:
|
|
if fnmatch.fnmatch(name.lower(), p.lower()):
|
|
files_list.append([name[:-3], os.path.join(root, name)])
|
|
break
|
|
|
|
return sorted(files_list, key=lambda x: x[0])
|