def create_tree(gi, found_lib, folders):
    """
    Create a directory structure in the given library.
    Returns the id of the last folder of the tree
    """
    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
    folder_to_create = []
    for f in folders:
        path += '/' + f
        if path in dist_f:
            print('Found folder ' + f)
            last_f_id = dist_f[path]['id']
        else:
            print('Did not find folder ' + f)
            folder_to_create.append(f)
    if len(folder_to_create) > 0:
        for f in folder_to_create:
            if last_f_id:
                print('Creating folder ' + f + ' in folder ' + last_f_id)
                f_c = gi.libraries.create_folder(found_lib, f, '', last_f_id)
            else:
                print('Creating folder ' + f + ' in root folder')
                f_c = gi.libraries.create_folder(found_lib, f, '')
            last_f_id = f_c[0]['id']
    return last_f_id
