Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

Using findAndReplaceWorkspacePaths in one directory (divide into sub folders) using Python?

$
0
0

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:

enter image description here

and this is the sub folders location (there are more MXD files in the other folders):

enter image description here


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:

  1. Why the code work only with the MXD files in the directory and not in the sub folders?
  2. Why the code printed so many lines?

Viewing all articles
Browse latest Browse all 767

Latest Images

Trending Articles



Latest Images