I would like to identify within a particular folder the .lyr files that have broken links. Some of these files are within multiple folders but all fall within one folder. My programming knowledge is fairly novice so I may use confusing or incorrect terminology.
I have been following the Q&A below, and have got the script to successfully identify .mxd's in a test folder only containing one .mxd file containing a broken .lyr file. When trying the .lyr script given in the same thread on a test folder containing a broken .lyr file both IDLE and Arc Desktop (10.2) crash.
Use arcpy.mapping to list broken data layers?
successful broken .lyr in mxd script:
import arcpy, os
path = r"M_XXX"
for root, dirs, files in os.walk(path):
for fileName in files:
basename, extension = os.path.splitext(fileName)
if extension == ".mxd":
fullPath = os.path.join(root, fileName)
mxd = arcpy.mapping.MapDocument(fullPath)
brknList = arcpy.mapping.ListBrokenDataSources(mxd)
for brknItem in brknList:
print "MXD: " + fullPath
print "\t" + brknItem.name
crash .lyr script:
import arcpy, os
path = r"M_XXX"
for root, dirs, files in os.walk(path):
for fileName in files:
basename, extension = os.path.splitext(fileName)
if extension == ".lyr":
fullPath = os.path.join(root, fileName)
mxd = arcpy.mapping.MapDocument(fullPath)
brknList = arcpy.mapping.ListBrokenDataSources(mxd)
for brknItem in brknList:
print "LYR: " + fullPath
print "\t" + brknItem.name