HOW TO

Organize items in the ArcGIS Online root folder into specific folders based on the last modified date using ArcGIS API for Python

Last Published: June 3, 2025

Summary

There are several times when items pile up in the root folder of a user in ArcGIS Online. When working with multiple items, it is often desirable to have the items organized to identify their usage in their respective months.

This article describes how to organize items in the ArcGIS Online Content page root folder by analyzing their last modified date and moving them into folders for the respective month of last modification using ArcGIS API for Python. The script can be run using a standalone .py file or through ArcGIS Notebook.

Procedure

  1. Import the necessary modules.
from arcgis.gis import GIS,ContentManager
import datetime
  1. Define the credentials for ArcGIS Online.
ago_gis=GIS('https://arcgis.com','Username','Password')
  1. Define the variables for the user, the root folder, and the names of the folders for the respective months.
me = ago_gis.users.me
rootitems=me.items(folder=None,max_items=1000)
year=['01-January','02-February','03-March','04-April','05-May','06-June','07-July','08-August','09-September','10-October','11-November','12-December']
  1. Create the folders according to the name specified in Step 3.
year1=['01-January','02-February','03-March','04-April','05-May','06-June','07-July','08-August','09-September','10-October','11-November','12-December']
for month in year1:
    ago_gis.content.create_folder(month)
  1. Create a list of items in the root folder and date modified.
DatemodifiedList=[]

for i in rootitems:
    d=(i.modified/1000)
    dt = datetime.datetime.fromtimestamp(d)
    tempstring=str(dt.date())+'-'+i.title
    DatemodifiedList.append(tempstring)
  1. Move all items to the folders for the corresponding months of the last date modified.
for item in rootitems:
    epochtime=(item.modified/1000)
    date_time = datetime.datetime.fromtimestamp(epochtime)
    itemYear=date_time.year
    Month=date_time.month
    item.move(year[Month-1])

DatemodifiedList
print ("Items are organized")

The following is a sample of the full script:

from arcgis.gis import GIS,ContentManager
import datetime

ago_gis=GIS('https://arcgis.com','User1_esri','useresri')

me = ago_gis.users.me
rootitems=me.items(folder=None,max_items=1000)
year=['01-January','02-February','03-March','04-April','05-May','06-June','07-July','08-August','09-September','10-October','11-November','12-December']

year1=['01-January','02-February','03-March','04-April','05-May','06-June','07-July','08-August','09-September','10-October','11-November','12-December']
for month in year1:
    ago_gis.content.create_folder(month)

DatemodifiedList=[]

for i in rootitems:
    d=(i.modified/1000)
    dt = datetime.datetime.fromtimestamp(d)
    tempstring=str(dt.date())+'-'+i.title
    DatemodifiedList.append(tempstring)

for item in rootitems:
    epochtime=(item.modified/1000)
    date_time = datetime.datetime.fromtimestamp(epochtime)
    itemYear=date_time.year
    Month=date_time.month
    item.move(year[Month-1])#The minus one is to indicate the position in the list

DatemodifiedList
print ("Items are organized")

Article ID: 000023812

Software:
  • ArcGIS Online
  • ArcGIS API for Python 1 x

Get support with AI

Resolve your issue quickly with the Esri Support AI Chatbot.

Start chatting now

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Start chatting now

Go to download options