Another example from our Python study group. This is a quick and dirty script to clip all shapefiles in a given directory by another specific shapefile. The output filenames are appended with “_clip” and the script takes care not to clip the clip file by itself.
import glob import os import sys import arcgisscripting try: # a directory path workspace = sys.argv # a directory for placing outputs filetoclipby = sys.argv except: print 'Usage: superclipper.py <workspace> <clipfile>' exit() gp = arcgisscripting.create() gp.Workspace = workspace shapefiles = workspace + "*.shp" for infile in glob.glob(shapefiles): # loop through once for each file, 'infile', matching # the pattern. if infile == filetoclipby: print infile,"is the file to clip by!" continue else: print infile + " will be clipped by " + filetoclipby outfile,extension = os.path.splitext(infile) outfile = outfile + "_clip" gp.Clip_analysis(infile,filetoclipby,outfile)