Automatically Find and Log All Broken Layers in Multiple Maps
Last week while teaching a Python class a student asked about a logical workflow, finding all maps with broken layers under a parent directory and reporting the results. Ideally this could be set up as a scheduled task and the results either written to a log file or better yet, emailed to somebody.
This appeared a straightforward opportunity to use the arcpy.da.Walk method with the optional 'Map' filter to return all maps. In my testing though, no matter what I tried, I could not get this method to return any maps.
Fortunately, maps are not located in a geodatabase and as a result, Python's os.walk method can be used instead. Since all map documents end with the mxd suffix, the results of os.walk can be filtered using the Python string.endswith method. Once all maps have been located under the parent directory, the arcpy.mapping.ListBrokenDataSources can be used to locate broken data sources.
The way the script is designed, if there are no broken map layers, no output will be created. However, if broken map layers exist, an output log file will be created in the parent directory listing all the maps and their respective broken layers. This is accomplished using the Python logging module. Although arguably overkill for such a simple task, if you are interested in modifying this script to support sending an email, it would only require taking advantage of logging.handlers.SMTPHandler (link) to send an email via an available smtp server.
Once I got the entire thing working, I uploaded it to a GitHub repository (link). From here you can download the script or fork it and improve it if you are versed in Python.