1import sys 2import typing 3import os 4import glob 5from pathlib import Path 6from typing import * 7 8 9class BasicTool: 10 @classmethod 11 def find_all_files(cls, folder: str, real_path: bool = True, apply_abs: bool = True, de_duplicate: bool = True, 12 p_filter: typing.Callable = lambda x: True) -> list: 13 filepath_list = set() 14 for root, _, file_names in os.walk(folder): 15 filepath_list.update( 16 [os.path.abspath(os.path.realpath( 17 os.path.join(root, f) if real_path else os.path.join(root, f))) if apply_abs else os.path.relpath( 18 os.path.realpath(os.path.join(root, f) if real_path else os.path.join(root, f))) for f in file_names 19 if p_filter(os.path.join(root, f))]) 20 if de_duplicate: 21 filepath_list = set(filepath_list) 22 filepath_list = sorted(filepath_list, key=str.lower) 23 return filepath_list 24 25 @classmethod 26 def get_abs_path(cls, path: str) -> str: 27 return os.path.abspath(os.path.expanduser(path)) 28 29 30if __name__ == '__main__': 31 for i in BasicTool.find_all_files(".", apply_abs=False): 32 print(i)