I have parent directory containing subfolders with layer files (.lyr) and I want to list Feature Classes, Geometry Types, server and user names for these files. Also I need Python to scan these files recursively. I am only a beginner in Python, so I don't really know how to do it. All I've done so far is here:

import os, fnmatch
import arcpy

for dirpath, dirnames, filenames in os.walk("F:\\"):
    for filename in filenames:
        if fnmatch.fnmatch(filename, "*.lyr"):
            lyr_filename = os.path.join(dirpath,filename)
            layers = arcpy.mapping.MapDocument(lyr_filename)
            for layer in arcpy.mapping.ListLayers(layers):

This code scan all the files in the subfolders, but it does not print the information I need. Version of my ArcCatalog is 10.0.

  • 1
    Welcome to GIS SE! As a new user be sure to take the Tour. Would you be able to edit your question to let us know whether the code you have presented works as far as listing the directories of layer files that you want it to, please? Assuming it does, I think you should next work out the code to take a single layer file and list its file [=feature?] class data source and geometry type.
    – PolyGeo
    Sep 7, 2015 at 10:35
  • 1
    Welcome to arcpy. You will want to use the arcpy.Describe object to get at the properties you want. The 10.0 version help is located here. Unfortunately you are cutting your teeth on a less user friendly object than most..help.arcgis.com/EN/arcgisdesktop/10.0/help/index.html#//… Sep 8, 2015 at 0:09

1 Answer 1


Eventually I used this code:

#importing libraries
import arcpy, os, fnmatch

#defining location of parent folder

#scanning through subfolders
for dirpath, dirnames, filenames in os.walk(BASE_DIRECTORY):

 for filename in filenames:

  #defining file type
  if fnmatch.fnmatch(filename, "*.lyr"):

   layerfile_full_path = os.path.join(dirpath, filename)
   layerfile_description = arcpy.Describe(layerfile_full_path)
   layerfile_layer = arcpy.mapping.Layer(layerfile_full_path)

    layer_map = arcpy.mapping.MapDocument(layerfile_full_path)
    for layer in arcpy.mapping.ListLayers(layer_map):

     layer_data = layer.dataSource.split('\\')

      #listing file path

      #listing server name

      #listing creator name

      #listing Oracle Table (Feature Class)

      #listing Geometry Type


    #if there are any errors, print 'fail' for these errors
    print(layerfile_full_path, 'fail')

I used the last code because of issues with database connection.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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