Search for a folder in the portal

613
1
06-10-2020 07:52 PM
MarceloRosensaft
New Contributor III

Hello,

I'd like to check if a folder exists in the portal before I create it. I don't see the feature_type = 'folder' option.

Thank you in advance,

Marcelo

0 Kudos
1 Reply
NikolajGrønholdt
Esri Contributor

You can user the folder property of a user. I've created an example, where I'm using my own user. I create a list with the titles of the folders, that I currently have in my content. If a folder with a given name is not found, it will be created

gis = GIS(portalURL, username, password)

me = gis.users.me
my_folders = (me.folders)

new_folder = 'my new folder'

folder_list = [i['title'] for i in my_folders]
if new_folder not in folder_list:
    gis.content.create_folder(new_folder)

However, it is worth noting that create_folder does nothing, if the folder already exists.

Link to api-reference