Select to view content in your preferred language

add a word to the start of an Enterprise Geodatabase Feature Class using Python.

524
2
Jump to solution
02-02-2023 08:13 AM
TomDonovan-Brady1
Emerging Contributor

I want to add a word to the start of an Enterprise Geodatabase Feature Class using Python.

I have around 2000 feature classes which I need to append a word such as 'County' to the start. 

so at the moment, I have

<GDB>.DBO.Ambulance_Bay

what I want is 

<GDB>.DBO.County_Ambulance_Bay. 

I have ArcGIS PRO 2.9 and would like to run this in the python window within ArcPRO. 

Any help will be greatly appreciated, as this will save time than manually renaming each file. 

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

A basic approach:

# This will try to rename your feature classes, be sure that you really want that!

arcpy.env.workspace = "C:/your_database.sde"  # database connection of the data owner (dbo in your example)
for fc in arcpy.ListFeatureClasses() + arcpy.ListTables():
    name = fc.split(".")[-1]
    new_name = "County_" + name
    try:
        arcpy.management.Rename(fc, new_name)
    except Exception as e:
        print(f"Could not rename {fc} to {new_name}: {e}")

 

To filter what classes and tables you rename:

ListFeatureClasses—ArcGIS Pro | Documentation

ListTables—ArcGIS Pro | Documentation


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

A basic approach:

# This will try to rename your feature classes, be sure that you really want that!

arcpy.env.workspace = "C:/your_database.sde"  # database connection of the data owner (dbo in your example)
for fc in arcpy.ListFeatureClasses() + arcpy.ListTables():
    name = fc.split(".")[-1]
    new_name = "County_" + name
    try:
        arcpy.management.Rename(fc, new_name)
    except Exception as e:
        print(f"Could not rename {fc} to {new_name}: {e}")

 

To filter what classes and tables you rename:

ListFeatureClasses—ArcGIS Pro | Documentation

ListTables—ArcGIS Pro | Documentation


Have a great day!
Johannes
TomDonovan-Brady1
Emerging Contributor

Dear Johannes, 

Thank you so much for your help I tested out of PROD, and it has done exactly what I wanted. You have saved me so much time. 

Thanks, 

Tom

0 Kudos