#Import standard library modules import arcgisscripting import os #Create the Geoprocessor object gp = arcgisscripting.create(9.3) #Set the input workspace #GP.workspace = sys.argv[1] #Set the workspace. gp.Workspace= "H:/temp_D/test" #Set the output workspace #outWorkspace = sys.argv[2] #Set the workspace. List all of the feature classes in the dataset outWorkspace= "H:/temp_D" #Get a list of the featureclasses in the input folder fcs = gp.ListFeatureClasses() # Loop through every item in the list that was just generated for fc in fcs: # delete the field CXXXX gp.deletefield (fc, "C*") gp.AddMessage(gp.GetMessages()) print gp.GetMessages()
Solved! Go to Solution.
# Create an empty list that will be populated with field names dropFieldNameList = [] # Use ListFields to get a list of field objects fieldList = arcpy.ListFields(inTable) for field in fieldList: #print field.name.upper() if not field.required: if field.name.upper().startswith('C'): dropFieldNameList.append(field.name) # Execute DeleteField to delete all fields in the field list. arcpy.DeleteField_management(inTable, dropFieldNameList)
if field.name.upper().startswith('C'):
#Import standard library modules import arcgisscripting import os #Create the Geoprocessor object gp = arcgisscripting.create(9.3) gp.toolbox = "management" #Set the input workspace #GP.workspace = sys.argv[1] #Set the workspace. gp.workspace= "H:/temp_D/test" #Set the output workspace #outWorkspace = sys.argv[2] #Set the workspace. List all of the feature classes in the dataset #Get a list of the featureclasses in the input folder fcs = gp.ListFeatureClasses() # Loop through every item in the list that was just generated for fc in fcs: fields = gp.ListFields(fc,"C*", "String") for field in fields: # if not field.endswith("D"): # delete the field CXXXX gp.deletefield (fc, field) del field del fields gp.AddMessage(gp.GetMessages()) print gp.GetMessages()
# Create an empty list that will be populated with field names dropFieldNameList = [] # Use ListFields to get a list of field objects fieldList = arcpy.ListFields(inTable) for field in fieldList: #print field.name.upper() if not field.required: if field.name.upper().startswith('C'): dropFieldNameList.append(field.name) # Execute DeleteField to delete all fields in the field list. arcpy.DeleteField_management(inTable, dropFieldNameList)
if field.name.upper().startswith('C'):
#Import standard library modules import arcgisscripting import os #Create the Geoprocessor object gp = arcgisscripting.create(9.3) #Set the input workspace #GP.workspace = sys.argv[1] #Set the workspace. gp.Workspace= "H:/temp_D/test" #Set the output workspace #outWorkspace = sys.argv[2] #Set the workspace. List all of the feature classes in the dataset outWorkspace= "H:/temp_D" #Get a list of the featureclasses in the input folder fcs = gp.ListFeatureClasses() # Loop through every item in the list that was just generated for fc in fcs: # Get the numeric code from the shapefile name numCode = fc[4:8] # Build the field name fieldName1 = "C"+numCode+"MS" fieldName2 = "C"+numCode+"MW" # delete the field CXXXX gp.deletefield (fc, fieldName1) gp.deletefield (fc, fieldName2) gp.AddMessage(gp.GetMessages()) print gp.GetMessages()
# Build the field name fieldName1 = "C"+numCode+"MS" fieldName2 = "C"+numCode+"MW" # delete the field CXXXX gp.deletefield (fc, fieldName1) gp.deletefield (fc, fieldName2)
gp.DeleteField_management(fc, [fieldName1, fieldName2]) gp.DeleteField_management(fc, "{0};{1}".format(fieldName1, fieldName2))