Select to view content in your preferred language

Get User Folder Name Provided the Folder ID

4405
4
07-09-2019 07:18 AM
mpboyle
Honored Contributor

Using the ArcGIS API for Python, is there a way to get the name of a user's folder if provided the folder ID?

For example, one of the properties of a portal item is "ownerFolder", which returns the id of the user's folder where the portal item is housed.  This is very helpful if the user has many folders when trying to find the item.  I'd like to know the name of this folder rather than just having the id.  Is there something similar to "content.get('item_id')" that can be used to return folder properties?

I'm aware of arcgis.gis.User("user_name").folders ... which returns a list of dictionaries providing information about all the folders a user has.  I don't really want to cross-reference all the user's folders and then match the id, but if that's the only way...

Tags (1)
4 Replies
TregChristopher
Frequent Contributor

Here's how I did  it:

gis = GIS(urlAGOL, userName, userPass)

gisUser = arcgis.gis.User(gis, "username of person who owns folder")
for fld in gisUser.folders:
    print(fld['id'], fld['title'])

0 Kudos
kurtia
by
Emerging Contributor
# GIS Connection
gis = GIS(portalurl,username,password,verify_cert=False)

# Get user and folders (user = gis.users.get(owner))
user = gis.users.get(username)
source_folders = user.folders 

for folder in source_folders:
    # Access properties using dot notation for 'title'
    logger.info(f"Folder Name: {folder.name}")
    # If you need to see all available attributes, you can print dir(folder)
    # print(dir(folder))
Joshua-Young
MVP Regular Contributor

@kurtia thank you for the example code. I used to use folder['title'] in my scripts and now that no longer works. Apparently folder.name is the way to do it now.

"Not all those who wander are lost" ~ Tolkien
0 Kudos