import pathlib


def encode_to_filesystem(value, codec):
    """
    Encode the given value using the given codec back Path object
    :param value: Unicode represented path
    :type value: str
    :param codec: Originally detected codec
    :type codec: str
    :return: Path object
    :rtype: pathlib.Path
    """
    return pathlib.Path(value.encode(codec).decode('utf-8', 'surrogateescape'))