AnsweredAssumed Answered

How can I delete a field with a different name in a list of feature classes?

Question asked by Gabino011 on Jan 17, 2015
Latest reply on Jan 19, 2015 by Gabino011

Hi All -


I am trying to delete a field in list of feature classes that changes name depending upon FC is in. This field in all FC has two things in common:


i) the field name starts with "FID_" in all the FCs,

ii) the field is located third [3rd] in the list of fields, right after the fields "FID" and "Shape".


With this in mind, I've tried a couple of things, as shown below, but they don't seem to work. I appreciate any ideas/suggestions you may have.


thanks !



import arcpy, os

from arcpy import env


env.workspace = r"C:\GIS\Track1\1_Orig\Track_int1"

wildcard = "xy**.shp"

fctype = "POLYLINE"



    fclist =  arcpy.ListFeatureClasses(wildcard, fctype)

    for fc in fclist:


# I'VE TRIED THIS:       

##        desc = arcpy.Describe(fc)

##        # Get a list of field objects from the describe object

##        fields = desc.fields


##        for field in fields:

##            if == "FID_**":

##                arcpy.DeleteField_management(fc, "FID_**")

##                break



            fieldList =  arcpy.ListFields(fc)

            fieldToDel =  fieldList[3:]

           arcpy.DeleteField_management(fc, fieldToDel)




    print arcpy.GetMessages(0)

    print arcpy.GetMessages(1)   

    print arcpy.GetMessages(2)