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
- ... namelist2.append(field2.name)
- ... if namelist2 == namelist:
- ... print namelist + "is common between the two shapefiles"
- ... x+=1
- ... y+=1