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

Printing MXD files name using ArcPy gives AssertionError: Invalid MXD filename?

$
0
0

I try to print all the MXD files name. The MXD files located in one directory (which is divided into folders and sub folders). Also in the sub folders there are MXD files. I work with this code:

import arcpy,os,sys,fnmatch  
from arcpy import env 

rootPath = r"G:desktopProject"
for root, dirs, files in os.walk(rootPath):
    env.workspace = root
    for mxdname in arcpy.ListFiles("*.mxd"):
        print root + '\' + mxdname
        mxd = arcpy.mapping.MapDocument(r"G:desktopProject\" + mxdname)
        print mxdname

It print all MXD files name in the main directory, but it don’t print MXD files in the sub directory.
This the error:

>>> 
G:desktopProjectlanduse__4___20013.mxd
landuse__4___20013.mxd
G:desktopProjectlanduse__5___20013.mxd
landuse__5___20013.mxd
G:desktopProjectproject.mxd
project.mxd
G:desktopProjectk20000landuse__1___20013.mxd

Traceback (most recent call last):
  File "G:desktoppython.py", line 9, in <module>
  mxd = arcpy.mapping.MapDocument(r"G:desktopProject\" + mxdname)
  File "C:Program Files (x86)ArcGISDesktop10.3ArcPyarcpyarcobjectsmixins.py", line 611, in __init__
   assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename")
AssertionError: Invalid MXD filename.
>>>

Viewing all articles
Browse latest Browse all 767

Trending Articles