Hi,
When i am running this code i am getting a Unicode error half way through. Not sure what mxd/layer file name is hanging it up (line 33) on but not sure where to put the fix (line 7 - or if this is the correct fix) either.
import arcpy, os
#code adds mxd name and layer path name to text file separated by a comma
arcpy.env.overwriteOutput = True
#def Utf8EncodeArray(oldArray):
#newArray = []
#for element in oldArray:
#if isinstance(element, unicode):
#newArray.append(element.encode("utf-8"))
#else:
#newArray.append(element)
#return newArray
path = "////serverpath"
#path2 =
mxdlst = []
txt = open("text file path", 'w')
print "making mxd list"
for root, dirs, files in os.walk(path):
for fname in files:
if fname.endswith(".mxd"):
mxd = root + '\\' + fname
mxdlst.append(mxd)
del mxd, fname
for mapdoc in mxdlst:
mxd = arcpy.mapping.MapDocument(mapdoc)
for df in arcpy.mapping.ListDataFrames(mxd, "*"):
for lyrlst in arcpy.mapping.ListLayers(mxd, "*", df):
if lyrlst.supports("DATASOURCE"):
txt.write(mapdoc + "," + lyrlst.workspacePath + "\\" + lyrlst.name + "\n")
print "adding" + mapdoc + "," + lyrlst.workspacePath + "\\" + lyrlst.name + "\n"
else:
txt.write(mapdoc + "," + lyrlst.name + "\n")
print "adding" + mapdoc + "," + lyrlst.name + "\n"
txt.close()
del mxd, df, lyrlst, mapdoc, mxdlst