I am new to Python but trying to rename hundreds of feature classes in a geodatabase. For instance, I have over 50 FCs named
Can I with my Python script to run in ArcGIS Pro to rename the
'LAND' part of the file to
'INFRA'? Instead of
'LAND_A' you would rename to
I know how to do this individually but not how to do for all the feature classes in a geodatabase. I have looked through many examples but have not yet found one that works.
This is the code I have been using that did not work so far:
arcpy.env.workspace = "C:\\Temp\\Test.gdb" for dataset in lstDatasets: lstFCs = arcpy.ListFeatureClasses("LAND_*", "", dataset) for fc in lstFCs: oldName = str(fc) newName = oldName.replace("LAND", "INFRA") arcpy.Rename_management(fc,newName)
I am getting the following error when I try to run the code:
"Traceback (most recent call last): File "<string>", line 1, in <module> NameError: name 'lstDatasets' is not defined"
I was able to get to the exact solution I needed by using the following script:
arcpy.env.workspace = "C:\\Temp\\test_GDB.gdb" lstDatasets = arcpy.ListDatasets() for dataset in lstDatasets: print (dataset) lstFCs = arcpy.ListFeatureClasses("LAND_*") for fc in lstFCs: print (fc) oldName = str(fc) newName = oldName.replace("LAND_", "INFRA_") arcpy.Rename_management(fc,newName)