Trying to delete multiple fields in all shapefiles in a folder issue

Discussion created by pjordan@drcog.org on Jul 13, 2012
Latest reply on Aug 13, 2012 by clthompson
I'm trying to modify a script where I can remove fields from all shapefiles in a specific folder.  The issue is I can only seem to do this for shapefiles I have specified in the gp.deletefield 'TEST.shp'.

  I don't want to specify a particular shapefile, I want this script to do this with a wildcard and all shapefiles in this folder.

  I am very new to Python, so I tried to use the wild card *.shp but that didn't do anything.

  So I researched and found the glob function.  Which I am having an issue trying to implement this into the script as
gp.deletefield glob.glob('*.shp', "Core; Comments")
of course will return an error.

So 2 questions are:
1) How can I get this script to remove the Core and Comment fields from all shapefiles in this folder?

2) Is there a way to make this script remove all *.shp files in all folders under the p:\\Traffic_Signals\KML\Jurisdictions rather than putting the script in each folder that contains a *.shp file?

  Thanks, I know this is pretty basic I am assuming, but just starting out here and needing to figure this out...

import arcpy
import arcgisscripting
import glob
gp = arcgisscripting.create()
gp.workspace = "p:\\Traffic_Signals\KML\Jurisdictions\TEST"
gp.toolbox = "management"

print "Removing Core and Comments from Shapefile"

    # Delete fields
    gp.deletefield ('TEST.shp', "Core; Comments")