I am trying to select and copy shapefiles from one folder to a new location based on if they intersect a polygon feature class. I am getting stuck in somewhere in the for loop.
EDIT: The goal is to copy the whole file if the extent of the shapefile intersects the polygon. I am not wanting to copy a subset of any shape.
# Generate list of shapefiles in the workspace
# Copy shapefiles in a list that intersect a polygon to a new location
import arcpy
import os
set environment settings
arcpy.env.workspace = 'E:\workspace\Contour_Shapefile'
set local variables
out_workspace = 'C:\localvariables\outworkspace\'
select_features = 'C:\localvariables\Project.gdb\AreaOfInterest'
use ListFeatureClasses to generate a list of shapefiles in the workspace shown above.
fc_list = arcpy.ListFeatureClasses()
#Execute CopyFeatures for each input shapefile that INTERSECT Area of interest.
i=1
for shapefile in fc_list:
out_featureclass = os.path.join(out_workspace, os.path.splitext(shapefile)[0])
arcpy.SelectLayerByLocation_management(shapefile, 'INTERSECT', select_features)
arcpy.CopyFeatures_management(shapefile, out_featureclass)
print(str(i) + ' copied ' + shapefile)
i += 1
else:
print( str(i) + ' MISSING')
i += 1
inpfile.close()