from pathlib import Path
from typing import List
from typing import Optional


def filter_file(root: str, file: Path, exclude: List[str]) -> Optional[Path]:
    """
    filter given file by their path.
    if one of the "forbidden folders" appears in the relative path of the current file, return None.
    otherwise return the file as is.
    :param root: root path to get relative path.
    :param file: file to be filtered
    :param exclude: list of strings of (sub)folders to exclude from analysis.
    :return: the file itself or none
    """
    parts = file.relative_to(root).parts
    if all(folder not in parts for folder in exclude):
        return file