[GIS] Listing all of contents of geodatabase with ArcPy

arcgis-10.0arcpyesri-geodatabase

This seems like a simple problem, but I have not found a way to accomplish it. I am writing a script that needs to record the paths of everything inside of a geodatabase to a text file, and later copy those files to a new location and zip them up.

I have been able to use arcpy.ListFeatureClasses to grab feature classes, and arcpy.ListRasters, and arcpy.ListDatasets, but how do I obtain a list of, say, Address Locators in my gdb? I haven't found a way to do it with arcpy. There should be a simple function that lists all of the contents of a geodatabase. Is there one I'm missing? Or is there any other way to accomplish this in python?

Best Answer

If your goal is simply copying a geodatabase with (most?) everything intact, you could use Copy_management to copy it to a file geodatabase, which you could then zip up using the Python zipfile module. There are also geoprocessing tools for geodatabase replication but I am not sure if address locators are included.

I am not aware of a way to list address locators with arcpy. You could suggest it on ArcGIS Ideas.

The last possibility I would suggest -- and this is definitely in the "any other way" category due to its complexity -- is to export the geodatabase to an ESRI XML Workspace document and parse it with Python's ElementTree XML API or lxml.

Currently there is no built-in way in arcpy to export an XML workspace document -- that's supposedly coming in 10.1 according to this ArcGIS Ideas post. However, you could write an ArcObjects command line application (like this one) and call it from Python using the subprocess module. Again I am not sure if things like address locators are included in the XML output though.

Related Question