from pathlib import Path


def path_exists(path, replace_keyword="", is_file=False):
    """
    Validates the existence of an file or directory path and returns it

    :param path: Path to be valided
    :param replace_keyword: Positional argument keyword which will be replaced, if required
    :param is_file: True, if path should be an existing file; False, if it should be a directory
    :return pathlib.Path: path to file or directory, if existent
    :raise Exception: In case file or directory path does not exist
    """
    p = Path(path.replace(replace_keyword, "")).resolve()

    if is_file and p.is_file():
        return p
    elif not is_file and p.is_dir():
        return p
    else:
        if is_file:
            message = "File path does not exist or is not a file."
        else:
            message = "Directory path does not exist or is not a directory."
        raise Exception(message)