Getting values from an attribute table. Please help

712
4
04-19-2012 05:39 AM
StevenWorkman
New Contributor III
Hello everyone.  Im very new to python. Just learning the basics right now. I really need to get to the point where I know how to automate some of these tasks I have at work. 

Anyways, I have a task right now where i need to find locations of diabase throughout the state.  I have a directory with a large number of folders (around 200) that contain personal geodatabases of each 7.5 min quadrangle.  In each mdb, there is a point shp file that has locations of different geologic features.  What I need to find out is which geodatabases contain the value "diabase" in the field "label". Is there a way to do this using python?  Any help is much appreciated.

-Steven
Tags (2)
0 Kudos
4 Replies
DarrenWiens2
MVP Honored Contributor
1.) List and loop through your folders (ListWorkspaces)
2.) List and loop through your geodatabases (ListWorkspaces)
3.) Use a SearchCursor to read the values in the point feature class
0 Kudos
StevenWorkman
New Contributor III
Thanks Darren.  I have been working on this procedure you gave, but I am not used to scripting so Im having some trouble. Can you possibly give an example on how you would loop through the workspace after you create a list?  This is what I have so far:

>>> import arcpy
>>> arcpy.env.workspace = "X:"
>>> workspaces = arcpy.ListWorkspaces("*","Folder")

What I tried to do is:
>>> for Folder in workspaces:
...  arcpy.ListWorkspaces("*","Access")
...
[]
[]
[]
[]
[]

And it kept on returning empty brackets.  I know there are .mdbs in each of my folders, but I cannot figure out how to list the geodatabases for each folder.  Thanks for any help.
0 Kudos
DarrenWiens2
MVP Honored Contributor
ListWorkspaces looks at the workspace environment (arcpy.env.workspace) for the path to look in. So, you need to change the workspace each time through the loop to look for mdbs in each folder.
import arcpy
arcpy.env.workspace = "X:"
ws = arcpy.ListWorkspaces("*","Folder")
print ws
for w in ws:
    arcpy.env.workspace = w 
    gdb = arcpy.ListWorkspaces("*", "Access")
    print gdb
0 Kudos
StevenWorkman
New Contributor III
Thanks for all your help Darren. I really appreaciate it.  Im guessing all I need to do now is loop through all of the datasets, and then use the SearchCursor to find the "diabase" value from the feature classe's attribute tables?
0 Kudos