Skip to main content
edited tags
Link
PolyGeo
  • 65.5k
  • 29
  • 115
  • 352
Made title better match question
Link
PolyGeo
  • 65.5k
  • 29
  • 115
  • 352

AssertionError: Invalid MXD filename from arcpy.mapping.MapDocument()?

Source Link

Invalid MXD filename

I'm trying to write a script that allows me to list the layers of each map document in a folder. However I keep getting this error after it displays the layers in the first map document:

Traceback (most recent call last): File "C:\Python27\ArcGIS10.1\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 326, in RunScript exec codeObject in main.dict File "C:\Users\Daimon Nurse\Desktop\DFMPROJECT\Scripts\editmapdocument8.py", line 10, in mxd = arcpy.mapping.MapDocument(file) File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\arcobjects\mixins.py", line 608, in init assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename") AssertionError: Invalid MXD filename.

This is the code I have tried:

import arcpy
import os

PATH2 = r"C:\Users\Daimon Nurse\Desktop\DFMPROJECT"
arcpy.env.workspace = PATH2
arcpy.env.overwriteOutput=True

for file in arcpy.ListFiles("*.mxd"):
    mxd = arcpy.mapping.MapDocument(file) 
    lyr = arcpy.mapping.ListLayers(mxd)
    print lyr

It worked for only the first iteration. Why?