import  os

class FileWalker:

    @staticmethod
    def get_files(root_filepath='./', filetype='gjf', file_filter=None):

        filetype = '.' + filetype
        gjf_file_path_list = []
        for root, _, files in os.walk(root_filepath):
            for file in files:
                if file.lower().endswith(filetype):
                    gjf_file_path_list.append(os.path.join(root, file))

        if file_filter:
            gjf_file_path_list_filter = []
            for item in gjf_file_path_list:
                if file_filter in item:
                    gjf_file_path_list_filter.append(item)
            return gjf_file_path_list_filter
        else:
            return gjf_file_path_list

    # level_list二维列表[[],[],[]]，第n行为n级目录，每列为n级目录的所有子目录
    @staticmethod
    def make_folders(level_list):

        from itertools import product
        # 使用itertools.product生成所有子列表的笛卡尔积
        combinations = list(product(*level_list))
        path_list = [''.join(combination) for combination in combinations]
        for path in path_list:
            try:
                os.makedirs(path, exist_ok=True)
            except:
                print(f'directory {path} make failed')
        return path_list