def find_tree(gi, found_lib, folders):
    """
    Look for a directory structure in the given library.
    Returns the id of the last folder of the tree if it was completely found
    """
    dist_folders = gi.libraries.get_folders(found_lib)

    dist_f = {}
    for f in dist_folders:
        dist_f[f['name']] = f

    path = ""
    last_f_id = None
    for f in folders:
        path += "/" + f
        if path in dist_f:
            print("Found folder " + f)
            last_f_id = dist_f[path]['id']
        else:
            raise Exception("Did not find folder '" + f + "'")

    return last_f_id