AnsweredAssumed Answered

Change field length using arcpy.FeatureClassToFeatureClass_conversion

Question asked by michael.carson on May 14, 2015
Latest reply on May 14, 2015 by michael.carson

My goal is to take a shapefile, change the length of one of the text fields, and save a new shapefile using arcpy.FeatureClassToFeatureClass_conversion.  You can do it using the tool's interface, just add a shapefile to it and the fields are listed, right click on a field to change it's properties and change the field length, then save to a new shapefile.


But how to do that using code?  I think you have to manipulate the field mapping to do it, but I cannot seem to find where you make the change for a particular field.  So far I have:


>>> inshp = "c:/temp/test1.shp"

>>> fms = arcpy.FieldMappings()

>>> fms.addTable(inshp)

>>> fms.fieldCount


>>> fm = fms.getFieldMap(0)

>>> fm.getInputFieldName(0)



So how do I change the field length for the CITY_NAME field and save it back to the field mapping?  Once that is done, I guess you put the field mapping back into the tool:


arcpy.FeatureClassToFeatureClass_conversion(inshp, "c:/temp", "test2.shp", "", field_mapping=fms)