AnsweredAssumed Answered

How to copy some fields from one feature class to an existing fc

Question asked by Zemregulus on Apr 25, 2019
Latest reply on May 7, 2019 by mbabinski1988

I need to copy some fields from one shapefile to another existing one, preferably using Arcpy. Below is my code that checks for common fields between two shapefiles. Can I use this and add code to copy the fields that are not already in the destination shapefile from the original? What function will do that for me? I do not want data to transfer over--just the fields. Thank you!

  • >>>#FIELDS is the list of fields from the shapefile to copy from
  • #FIELDS2 is the list of fields already in the shapefile to copy to
  • fields = arcpy.ListFields("G:/Working Folder/Backup.gdb/PubData_RoadCenterlines")
  • ... fields2 = arcpy.ListFields(r"G:\Data\External\Fairfield_County\Dupage_Centerlines_Web_Mercator_1984.shp")
  • ... namelist = []
  • ... namelist2 = []
  • ... x = 0
  • ... y = 0
  • ... for field in fields:
  • ...    #populate NAMELIST[] with FIELDS 
    • namelist.append(field.name)
  • ...   #check the to shapefile for fields it already has and are common with the from shapefile
    • for field2 in fields2:
  • ...         namelist2.append(field2.name)
  • ...         if namelist2[x] == namelist[y]:
  • ...             print namelist[y] + "is common between the two shapefiles"
  • ...        x+=1
  • ...     y+=1

Outcomes