I just need a simple sript that will copy a feature layer and convert it to a shapefile with just a four of the original field names. I know how to do this manually but I need python script so it can automatically every morning. I tried arcpy.TableToTable_conversion and FeatureClassTo FeatureClass but can't seem to figure it out how to select only those field name that are required for my project.
Thanks,
Use the field mappings:
fieldmappings = arcpy.FieldMappings()
fieldmappings.addTable(fc)
keepfields = ['F1','F2','F3','F4']
# Removing unwanted fields
for field in fieldmappings.fields:
if all([not field.required, field.name not in keepfields]):
fieldmappings.removeFieldMap(fieldmappings.findFieldMapIndex(field.name))
arcpy.FeatureClassToFeatureClass_conversion(fc, 'outdir', 'outname', '', fieldmappings)
If it's always the same four fields, the easiest way to do it is to do it manually once, then open up your geoprocessing history and copy as a python command/send to the python window and copypaste into your project.