I have a large number of archive shapefiles which need their attribute fields tidying. During their history they have gone through various merge processes, which have resulted in some of the shapefiles having duplicate attribute fields where the system has auto assigned the suffix '_1', '_2' etc to the attribute field name. The attribute fields vary between shapefiles, and so can the duplicated attributes. Therefore I am thinking a wildcard solution rather than a definitive list removal solution is the way to go.
I am looking for an arcpy script which will run through multiple shapefiles from input source folder, remove all duplicate attribute fields suffixed with _1, _2, _3 etc and save the updated shapefiles to an output folder.
I have managed to perform the required task on a single shapefile using the acrpy code below. I use the "1" as a wildcard which seems to work in removing all attribute fields with suffix of _1, and the same for *_2 and *_3 attributes:
import arcpy fc = 'd:\\Input\\Buildings.shp One = [f.name for f in arcpy.ListFields(fc,"*1*")] arcpy.DeleteField_management(fc, One) Two = [f.name for f in arcpy.ListFields(fc,"*2*")] arcpy.DeleteField_management(fc, Two) Three = [f.name for f in arcpy.ListFields(fc,"*3*")] arcpy.DeleteField_management(fc, Three)
However, I understand this is very clumsy and it falls over if the input shapefile does not contain any attribute filed that contains an underscore digit suffix. So I am looking for a more elegant solution for removing these duplicated attribute fields using ArcPy.