matthew.f.tenold

Python issue finding and replacing file path's for mxd's in a loop

Discussion created by matthew.f.tenold on Aug 3, 2012
Latest reply on Aug 6, 2012 by clthompson
Hi everyone,

I am trying to find and replace workspace path's for a person changing root folder names.  The main issue is that all of the maps are pointed to shapefile in multiple folders and folders inside of eachother.   I am trying to write a python script that will loop through each subfolder looking for the shapefiles' source path and repairing the data path to the new root folder name, since the folder structure will remain the same other than the root folder name changing.

Here is my current code.  Any help would be much appreciated thanks.

import arcpy
import os
rootdir = r"G:\Working\Matt Tenold\*"
for subdir, dirs, files in os.walk(rootdir):
for filename in files:
  fullpath = os.path.join(subdir, filename)
  print filename
  if os.path.isfile(fullpath):
      basename, extension = os.path.splitext(fullpath)
      if extension.lower() == ".mxd":
   mxd = arcpy.mapping.MapDocument(fullpath)
    # Search-and-replace to fix up data source paths.
    mxd.findAndReplaceWorkspacePaths(r"G:\Working\MattTenold\*", r"G:\Working\Matt Tenold\*", False)
   mxd.save()

del df
del mxd

Outcomes