AnsweredAssumed Answered

Delete fields sharing the first five letter and numbers

Question asked by helenak on Jan 2, 2013
Latest reply on Jan 3, 2013 by helenak
System ArcGIS 9.3
Python 2.5


I have 100 polygon shapefiles in a folder.
Their names are geoc0923, geoc2344, geoc3264, ???, and geoc9833.
Each of them has an attribute table of several fields.

For example, geoc0923 have fields: C0923 (string), C0923R (long), C0923MS (long), C0923MW (long).[ATTACH=CONFIG]20389[/ATTACH]
Now I want to delete the fields (long),

Also, I want to keep the CXXXX field (string).

Please kindly advise how to indicate the field (long) in the python code below.
Thank you.

#Import standard library modules import arcgisscripting import os  #Create the Geoprocessor object gp = arcgisscripting.create(9.3)  #Set the workspace. gp.Workspace= "H:/temp/test"  #Set the workspace. List all of the feature classes in the dataset outWorkspace= "H:/temp"  #Get a list of the featureclasses in the input folder fcs = gp.ListFeatureClasses("geoc*")  # Loop through every item in the list that was just generated for fc in fcs:      # Break out the name, no path or extension, using the describe object.     desc = gp.describe(fc)     featureName =      #Validate the new feature class name for the output workspace.     outFeatureClass = outWorkspace + os.sep +gp.ValidateTableName(fc,outWorkspace)     gp.Toolbox = "Data Management"   #Select CXXXXR  #-----------------------------------------------------------------              # Loop through every item in the list that was just generated      for field in fields:          gp.toolbox = "Data Management"         gp.addMessage(type(field))          # Select records (C*, i.e. C7658)         # Make temporary featureclasses         gp.toolbox = "Data Management"          #get file name         fcName, fcExt = os.path.splitext(fc)           #build field name         fieldName = fcName + "R"              # delete the field "CXXXXR"         gp.deletefield (fc, fieldName)