Skip to content

Instantly share code, notes, and snippets.

@nuriozbey
Last active September 6, 2022 10:54
Show Gist options
  • Select an option

  • Save nuriozbey/df98b9ec5159999160b7a8b861a682d0 to your computer and use it in GitHub Desktop.

Select an option

Save nuriozbey/df98b9ec5159999160b7a8b861a682d0 to your computer and use it in GitHub Desktop.
"""
Usage:
folder_url = "/teams/<channel>/Shared Documents"
list_folders(ctx = ctx, relative_url = folder_url)
"""
def list_folders(ctx,relative_url):
libraryRoot = ctx.web.get_folder_by_server_relative_path(relative_url)
ctx.load(libraryRoot)
ctx.execute_query()
#if you want to get the folders within <sub_folder>
folders = libraryRoot.folders
ctx.load(folders)
ctx.execute_query()
url_list = []
for myfolder in folders:
print("Folder name: {0}".format(myfolder.properties["ServerRelativeUrl"]))
url_list.append(myfolder.properties["ServerRelativeUrl"])
return url_list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment