[GIS] Invert Deleting multiple fields with delete tool in ArcGIS Desktop

arcgis-10.1arcgis-desktopfields-attributes

I am using ArcGIS Desktop 10.1 SP1.

I have a feature (polygon) with nearly 60 fields in it. Now I want to delete all fields except 20(or a list of) and they are not one after one, no they are somewhere in the droplist. But to select for a tons around 40 feature shape files would be a huge searching and clicking time…because the update for every new loaded feature his droplist and i can start searching again and again.

Normally it must be go the opposite way…or?

I am looking for a tool or script by "inverse droping". From the web I did not get a useful solution.

Best Answer

If you stay with the tools, you can first select all the fields then unselect the ones that you want to keep.

You could also create a Python script to do this, but if you don't have a fixed rule and you need to enter the field names manually, this will not help.

import arcpy   

# if you can use a key to identify the fields to remove, then it's solved
fields = arcpy.ListFields(fc) 

# manually enter field names to keep here
# include mandatory fields name such as OBJECTID (or FID), and Shape in keepfields
keepFields = ["OBJECTID", "Shape","fld1","fld3","fld20"]

dropFields = [x.name for x in fields if x.name not in keepFields]
# delete fields
arcpy.DeleteField_management(fc, dropFields)     
Related Question