I try to use ‘findAndReplaceWorkspacePaths’ function on MXD files using ArcView 10.3.1. The MXD files located in one directory (which is divided into folders and sub folders). Also in the sub folders there are MXD files.
This is the directory content location:
and this is the sub folders location (there are more MXD files in the other folders):
I write in python 2.7:
import arcpy,os,sys,fnmatch
from arcpy import env
rootPath = r"G:desktopProject"
for root, dirs, files in os.walk(rootPath):
env.workspace = r"G:desktopProject"
for mxdname in arcpy.ListFiles("*.mxd"):
print mxdname
mxd = arcpy.mapping.MapDocument(r"G:desktopProject\" + mxdname)
mxd.findAndReplaceWorkspacePaths(r"D:PROJECTSgreen_linegislayers", r"G:PROJECTSgreen_linegislayers")
print 'findAndReplaceWorkspacePaths'
mxd.save()
del mxd
The result is:
>>>
landuse__3___20013.mxd
findAndReplaceWorkspacePaths
landuse__4___20013.mxd
findAndReplaceWorkspacePaths
landuse__3___20013.mxd
findAndReplaceWorkspacePaths
landuse__4___20013.mxd
findAndReplaceWorkspacePaths
landuse__3___20013.mxd
findAndReplaceWorkspacePaths
landuse__4___20013.mxd
findAndReplaceWorkspacePaths
landuse__3___20013.mxd
findAndReplaceWorkspacePaths
landuse__4___20013.mxd
findAndReplaceWorkspacePaths
landuse__3___20013.mxd
findAndReplaceWorkspacePaths
landuse__4___20013.mxd
findAndReplaceWorkspacePathslanduse__3___20013.mxd
findAndReplaceWorkspacePaths
landuse__4___20013.mxd
findAndReplaceWorkspacePaths
landuse__3___20013.mxd
findAndReplaceWorkspacePaths
landuse__4___20013.mxd
findAndReplaceWorkspacePaths
landuse__3___20013.mxd
findAndReplaceWorkspacePaths
landuse__4___20013.mxd
findAndReplaceWorkspacePaths
landuse__3___20013.mxd
findAndReplaceWorkspacePaths
landuse__4___20013.mxd
findAndReplaceWorkspacePaths
>>>
Now, there are two problems:
- Why the code work only with the MXD files in the directory and not in the sub folders?
- Why the code printed so many lines?