I have a folder of shapefiles which I want to append to project geodatabase feature classes using ArcPy. So far, as I am testing with just a few shapefiles, the script works fine as long as all the fields match and there is no field mapping involved. However, I would like to include field mapping with the code, but being relatively new to Python and ArcPy, I am having trouble understanding the best way to do this.
I would like to match the following fields: "reference" (in shapefile) with "ID" (feature class in GDB) and "riskcategory" (in shapefile) with "risk" (feature class in GDB).
My current code is below:
import arcpy
import os
#Set up workspace
workspace_in = arcpy.GetParameterAsText(0)
workspace_out = arcpy.GetParameterAsText(1)
arcpy.env.workspace = workspace_in
#Set target datasets
targetPt = os.path.join(workspace_out, "tree_location_pt")
targetPly = os.path.join(workspace_out, "tree_location_ply")
#get a list of shapefiles
survey = arcpy.ListFeatureClasses()
#loop shapefiles in folder
for fc in survey:
if fc == "export_Point.shp":
arcpy.management.Append(fc, targetPt, "NO_TEST")
elif fc == "export_Polygon.shp":
arcpy.management.Append(fc, targetPly, "NO_TEST")
field_mappingparameters you have attempted and include any error(s).