bl4k3

DeleteField_management (delete all except 3 fields)

Discussion created by bl4k3 on Sep 14, 2012
Latest reply on Jul 24, 2017 by DougHaller
I have a shape that has twenty fields or more.  I want to delete all fields except three using python code.  I thought of using DeleteField_management, but it looks like I have to know the name of the fields I want to delete.  Unfortunately, in my case I only know the name of the fields I want to keep.  Is there a way to delete all the fields except the 3 I want to keep which are ("UGISID", "LBL_X", "LBL_Y")?  or is there a way to export out the shape with only the 3 fields and then deleting the one with 20?

Again,  the issue is: Everytime I use this script, a new shape will be used and all I need are the three fields and there is no way to know what fields need to get deleted, only that I need ("UGISID", "LBL_X", "LBL_Y") when it comes out the other end.

Outcomes