This question already has an answer here:
I have a shapefile composed of a number of polygons. The shapefile has table column entitled as name (field: NAME).
How can I export with ArcPy each polygon so I get a shapefile for each one and it's name (ex: name.shp) corresponds with the ones in the table column?
I've attempted to use the following code:
import arcpy shp = "c:/temp/folder/shapefile.shp" TargetFolder = "c:/temp/folder" query = """"NAME" > 2""" with arcpy.da.SearchCursor(shp, ["NAME","SHAPE@"], query) as cursor: for row in cursor: arcpy.FeatureClassToFeatureClass_conversion(row, TargetFolder, row)
I get the error code: An invalid SQL statement was used.
I used code from Export to SHP with ArcPy with query as the basis for mine.