from pathlib import Path


def remove_front_back_matter(filename: Path, OUTPUT: Path) -> None:
    """Remove legal information from Project Gutenberg files.
    
    Reads the file with 'filename' and outputs the same file with
    the "proc" word appended at the end of the filename in the
    'OUTPUT', but without the lines at the beginning and
    at the end of the original file containing legal information
    from Project Gutenberg.
    
    Parameters:
    filename: Path - name of the file to process
    out_folder: Path - name of the outout folder
    
    Returns:
    None
    """
    assert filename.exists(), f"File {filename} does not exist!"
    if not OUTPUT.exists():
        OUTPUT.mkdir()
        print(f"Directory {OUTPUT} created!")
    lines = []
    write = False
    with open(filename, "r", encoding="UTF-8") as f:
        for line in f:
            if line.strip().startswith("*** START OF"):
                write = True
                continue
            elif line.strip().startswith("*** END OF"):
                write = False
                break
            if write:
                lines.append(line)
    with open(OUTPUT / (filename.stem + "_proc.txt"), "w", encoding="UTF-8") as g:
        for line in lines:
            g.write(line)
    return None