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.
Solved! Go to Solution.
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
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
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