from pathlib import Path


def _transform_path(path, search_str, replace_str):
    """
    This function replaces a single directory in the given path by the given string and returns the new path.

    :param path (str || Path): The path that has to be transformed.
    :param search_str (str): The directory that has to be changed.
    :param replace_str (str): The directory that the subdirectory has to be changed to.

    Returns:
        (Path): The new path if the replacement was successful, else the original path.

    """
    result = Path(path)
    subdirectories = list(path.parts)
    if search_str in subdirectories:
        subdirectories[subdirectories.index(search_str)] = replace_str
        result = Path(*subdirectories)
    return result