Select to view content in your preferred language

List all Layer Files in a directory which reference a specific Feature Class?

1222
1
10-20-2011 06:50 AM
847396730
Frequent Contributor
Good morning! We have changed our data to allow temporal tracking, which means that all shared layer files which reference our ROADS feature class require the addition of  AND "RECORD_STATUS" = 5 to their definition query.  We have a couple hundred layer files in lots of folders; I can't be certain which ones reference this feature class.  How can I write a python script to comb through the directory and return all layer files which reference the ROADS feature class?  Thanks!
Tags (2)
0 Kudos
1 Reply
ChristopherStorer
Emerging Contributor
There's certainly functionality to do this.  Something like:

folderPath = 'C:\temp'
targetDataSource = 'C:\mapping\shapefile.shp'

files = os.listdir(folderPath)
for curFile in files:
    if curFile.endswith(".txt"):
        for lyr in arcpy.mapping.ListLayers(curFile):
            if lyr.dataSource == targetDataSource:
                print("Outdated layer found at " + lyr.lyr_file_path)


It's a little if-happy, but try that angle and see what you get.
0 Kudos