HOW TO

Rename multiple feature classes using ArcGIS API for Python

Last Published: April 5, 2023

Summary

In ArcGIS Pro, the General toolset contains tools to perform general data management operations on a geodatabase table or feature class. These modifications can be made by running a Python script in ArcGIS Pro. This article provides the workflow to rename multiple feature classes (as shown in the Catalog pane below) using ArcGIS API for Python.

The Catalog pane with all the feature classes

Procedure

  1. Start ArcGIS Pro and open the project.
  2. To open the Python window, on the top ribbon, click Analysis, click the Python drop-down list arrow and select Python Window.
The Python window icon in the Python drop-down box on the Analysis tab
  1. Specify the following script in the Python window.
    1. Import the necessary modules.
import arcpy
  1. Specify the workspace with the file geodatabase folder path.
arcpy.env.workspace = r"<gdbFolderPath>"
  1. Specify the ArcPy function to apply the changes to all the feature class names and aliases. In this example, the <separator> specifies the separator to use when splitting the string. The <maxSplit> specifies the index number of the part to split in relation to the separator, -1 represents 'all occurrences'. The <addToFeatureClassName> is named as Test_.
for fc in arcpy.ListFeatureClasses() + arcpy.ListTables():
    name = fc.split("<separator>")[<maxSplit>]
    new_name = "<addToFeatureClassName>" + name
    try:
        arcpy.management.Rename(fc, new_name)
    except Exception as e:
        print(f"Could not rename {fc} to {new_name}: {e}")

The code block below demonstrates the full working script.

import arcpy
arcpy.env.workspace = r"C:\Users\ISC-DT27\Documents\Article work\29660\LabelMapFeatures\Portland Labels.gdb"
for fc in arcpy.ListFeatureClasses() + arcpy.ListTables():
    name = fc.split(" ")[-1]
    new_name = "Test_" + name
    try:
        arcpy.management.Rename(fc, new_name)
    except Exception as e:
        print(f"Could not rename {fc} to {new_name}: {e}")

The image below shows the updated feature class names using Python in ArcGIS Pro.

The Python script and results of the updated feature class names

Article ID: 000029660

Software:
  • ArcGIS Pro 3 1
  • ArcGIS Pro 3 0
  • ArcGIS Pro 2 x

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options