lstDatasets = arcpy.ListDatasets("*") for dataset in lstDatasets: lstFCs = arcpy.ListFeatureClasses("road_*", "", dataset) for fc in lstFCs: if "NS" in fc: oldName = str(fc) newName = oldName.replace("road", "RD") newName = newName.replace("NS", "_NS12_13") arcpy.Rename_management(fc, newName)
Any help on how to replace the last 3 characters across multiple feature class names?
I know this is many years after the initial post, but holy cow, thank you so much for this. Using this, I was able to automate renaming 500+ feature classes.
Chris, you would concatenate the original featureclass name with the new suffix.
newName = str(fc) + '_1045'
When I run this it only replaces the text for the last "newName" line, so in your example it would only replace the "ns" with "_NS12_13" and ignore the line that replaces "road". Any idea why that might be?
Hey Guys,
Thanks for the information. I'm looking to do the opposite where I would like to create a suffix on many different feature class names like '_1405' for example.
Thanks,
Chris
Hi Jake,this worked great, thanks! I also wanted to see if the just "ns" portion could also search featureclasses that are written in capital letters such as "NS"?Is there a way to make this case- insensitive?thanks again!
import arcpy from arcpy import env env.workspace = r"C:\temp\python\test.gdb" lstDatasets = arcpy.ListDatasets("*") for dataset in lstDatasets: lstFCs = arcpy.ListFeatureClasses("road_*", "", dataset) for fc in lstFCs: oldName = str(fc) newName = oldName.replace("road", "RD") newName = newName.replace("ns", "_NS12_13") arcpy.Rename_management(fc, newName)
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.