def remove_obsolete_folders(states, path):
    """Removes obsolete state machine folders

    This function removes all folders in the file system folder `path` that do not belong to the states given by
    `states`.
    
    :param list states: the states that should reside in this very folder
    :param str path: the file system path to be checked for valid folders
    """
    elements_in_folder = os.listdir(path)
    # find all state folder elements in system path
    state_folders_in_file_system = []
    for folder_name in elements_in_folder:
        if os.path.exists(os.path.join(path, folder_name, FILE_NAME_CORE_DATA)) or \
                os.path.exists(os.path.join(path, folder_name, FILE_NAME_CORE_DATA_OLD)):
            state_folders_in_file_system.append(folder_name)

    # remove elements used by existing states and storage format
    for state in states:
        storage_folder_for_state = get_storage_id_for_state(state)
        if storage_folder_for_state in state_folders_in_file_system:
            state_folders_in_file_system.remove(storage_folder_for_state)

    # remove the remaining state folders
    for folder_name in state_folders_in_file_system:
        shutil.rmtree(os.path.join(path, folder_name))
Removes obsolete state machine folders

    This function removes all folders in the file system folder `path` that do not belong to the states given by
    `states`.
    
    :param list states: the states that should reside in this very folder
    :param str path: the file system path to be checked for valid folders