0

I currently have a script that will select and delete all the values less than 0.1 in a column. The script below works, however it specifies a specific .shp, I want to batch this so it runs through all the shapefiles in a geodatabase

import arcpy
arcpy.SelectLayerByAttribute_management("Sr90_contour","NEW_SELECTION",'"Contour" < 0.1')
arcpy.DeleteFeatures_management("Sr90_contour")
2

You can specify the GDB as your workspace and then use the arcpy.ListFeatureClasses() function to get all the names of the features in that GDB:

import arcpy

arcpy.env.worskapce = r'C:\path\to\my.gdb'

for fc in arcpy.ListFeatureClasses():
    arcpy.MakeFeatureLayer_management(fc, "lyr")
    arcpy.SelectLayerByAttribute_management("lyr", "NEW_SELECTION", '"Contour" < 0.1')
    arcpy.DeleteFeatures_management("lyr")

Note that this will only work if all your feature classes have the Contour field.

  • Thanks, However when I run that I get the following error...…... runtime error Traceback (most recent call last): File "<string>", line 6, in <module> File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 7221, in SelectLayerByAttribute raise e ExecuteError: The value cannot be a feature class ERROR 000840: The value is not a Raster Layer. ERROR 000840: The value is not a Mosaic Layer. – JHR Aug 13 at 15:24
  • You need to create an in-memory feature layer for every feature class first before making a selection on it. See here – mdholl6188 Aug 13 at 15:32
  • @JHR See the edit I just made to the question taking into accout the comment from mdholl6188. Also, delete your answer, as it does not really answer your question but is rather a comment or edit. – Marcelo Villa Aug 13 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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