I'm trying to use a script to batch clip all files in a folder, then saved with a _clipped.shp at the end of the original, I need a script that is something like this:

arcpy.env.workspace = "E:\\folder\\test_input"

# Set local variables
in_features = arcpy.env.workspace
clip_features = "E:\\folder\\mask\\boundary.shp"
out_feature_class = "_clipped.shp"
# Execute Clip
for f in arcpy.env.workspace
    arcpy.Clip_analysis(f, clip_features, f(name) + out_feature_class)

Where the f(name) 'points' to the orignal shapefile name and then 'appends' _clipped.shp at the end and then saves and performs this process iteratively for each file.

Also should I have a different output folder for the clipped features?

The reason I'm doing this is because the actual batch clip feature of the clip tool is not working for some reason.

  • 1
    You need to use ListFeatureClasses to get a handle of the datasets in a folder, see the help file for correct usage.
    – Hornbydd
    Apr 23, 2021 at 13:30

1 Answer 1


Try this:

import arcpy, os

arcpy.env.workspace = r'C:\GIS\data\testdata\clip' #Your folder with the shapefiles to be clipped
outfolder = r'C:\GIS\data\testdata\clipout'
cutter = r'C:\GIS\data\testdata\clippolygon.shp'

for fc in arcpy.ListFeatureClasses(): #List shapes in workspace
    print 'Clipping: ', fc
    arcpy.Clip_analysis(in_features=fc, clip_features=cutter, out_feature_class=os.path.join(outfolder, fc.replace('.shp','_clipped.shp')))

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.