0

I have GDB files located in many sub-Folders and sub-sub-Folders. All Sub Folders are located in one large directory i asked it for layer file in Add multiple Layer files in subdirectories to mxd using python I use this code:

import arcpy  
import os  

workspace = r"C:\Project\layers"
mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]
walk = arcpy.da.Walk(workspace, datatype="Layer")
for dirpath, dirnames, filenames in walk:
    for filename in filenames:
        arcpy.mapping.AddLayer(df, arcpy.mapping.Layer(os.path.join(dirpath, filename)))
        print filename
    mxd.save()
del mxd

How can i do it for GDB files ?

newGIS
  • 4,062
  • 4
  • 41
  • 92
  • It's not possible to add a GDB to an mxd... with arcpy you can't even add a feature class. All you can add is a layer. What do you exactly want to do? See this question for a possible option. – GISGe Jan 20 '15 at 12:48
  • 1
    @GISGe I agree that it makes no sense to try and add a *.gdb to a map but this Q&A shows how you can add a feature class (shapefile) as a layer: http://gis.stackexchange.com/questions/4882/adding-shapefile-as-layer-in-arcgis-desktop-using-python-arcpy – PolyGeo Jan 20 '15 at 13:01
  • @PolyGeo that's true indeed! So the documentation is wrong. Those Layer functions are less restrictive than they should then. Thanks for pointing to this. – GISGe Jan 20 '15 at 13:14

1 Answers1

1

So based on @PolyGeo's comment you should just replace the datatype parameter in the arcpy.da.Walk() function:

walk = arcpy.da.Walk(workspace, datatype="FeatureClass")

The rest of the code can be reused as it is.

GISGe
  • 9,674
  • 19
  • 41