from pathlib import Path


def make_dirlist(folder, exclude_folders, fnpatterns, exclude_fnpatterns):
    """List of all files matching fnpatterns and not matching exclude_fnpatterns

    Args:
        folder (str): Directory to look into
        exclude_folders (List[str]): Directories to skip
        fnpatterns (List[str]): Patterns to match
        exclude_fnpatterns (List[str]): Patterns to exclude

    Returns:
        List[PosixPath]: List of all matching files
    """
    matches = []
    for fnpattern in fnpatterns:
        matches.extend(Path(folder).rglob(fnpattern))
    matches = set(matches)
    for exclude_fnpattern in exclude_fnpatterns:
        matches = matches - set(Path(folder).rglob(exclude_fnpattern))
    return [
        path for path in matches
        if not any([
            Path(exclude_folder) in path.parents
            for exclude_folder in exclude_folders
        ])
    ]