import os


def set_working_directory_to_app():
    project_root_dir_name = "App"
    # Get the current working directory
    current_dir = os.getcwd()

    # Split the current directory into parts
    path_parts = current_dir.split(os.sep)

    # Check if 'App' is part of the current path
    if project_root_dir_name in path_parts:
        # Reconstruct the path up to and including the 'App' directory
        app_index = path_parts.index(project_root_dir_name)
        app_path = os.sep.join(path_parts[: app_index + 1])

        # Change to the 'App' directory if not already there
        if current_dir != app_path:
            os.chdir(app_path)
            print(f"Changed directory to project root: {app_path}")
        else:
            print(f"Already in the project root: {current_dir}")
    else:
        raise FileNotFoundError(
            f"The project root directory '{project_root_dir_name}' was not found in the current path."
        )
