Book Image

Programming ArcGIS with Python Cookbook, Second Edition

By : Donald Eric Pimpler, Eric Pimpler
Book Image

Programming ArcGIS with Python Cookbook, Second Edition

By: Donald Eric Pimpler, Eric Pimpler

Overview of this book

Table of Contents (22 chapters)
Programming ArcGIS with Python Cookbook Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Finding broken data sources in all map documents in a folder


A common scenario in many organizations involves the movement of data from one workspace to another or from one workspace type to another. When this happens, any map documents or layers that reference these data sources become broken. Finding each of these data sources can be a huge task if undertaken manually. Fortunately, you can create a geoprocessing script that will find all broken data sources in a folder or list of folders.

Getting ready

In this recipe, you will learn how to recursively search directories for map document files, find any broken data sources within these map documents, and write the names of the broken data layers to a file.

How to do it...

Follow these steps to learn how to find all broken data sources in all map documents in a folder:

  1. Open IDLE and create a new script window.

  2. Import the arcpy and os packages:

    import arcpy.mapping as mapping, os
  3. Open a file that you will use to write the broken layer names:

    f = open...