AnsweredAssumed Answered

Write to Text; Directory Name

Question asked by jared_pilbeam on Jun 20, 2017
Latest reply on Jun 21, 2017 by iamurray

The script below iterates through a folder and determines what version of ArcMap (9.0 - 10.5) each MXD was saved in then  writes to a text file. The file is saved with the string in line 11. It's telling me this script also has a syntax error in line 11, but I can not see why? I'm running PythonWin 2.7 on Windows 10.

 

What I want is to have the file named after the directory (i.e. whatever the user puts in the workspace parameter of the script tool). Is there a way to do that?

import glob, os, sys
from oletools.thirdparty import olefile
import arcpy

arcpy.env.overwriteOutput = True

Workspace = arcpy.GetParameterAsText(0)
mxdFiles = glob.glob(os.path.join(Workspace, '*.mxd')

# Write to textfile
txtFile = open(Workspace + "{}".format("Identify ArcMapVersion.txt"), "w")
txtFile.write("The folling list is the file path(s) to the MXD(s) followed by the ArcMap version" + "\n")
txtFile.write("-------------------------------------------------------------------" + "\n")

def mxd_version(filename):
    ofile = olefile.OleFileIO(filename)
    stream = ofile.openstream('Version')
    data = stream.read().decode('utf-16')
    version = data.split('\x00')[1]
    return version

for mxdFile in mxdFiles:
    fileName = os.path.basename(mxdFile)
    print mxdFile, (mxd_version(mxdFile))
    arcpy.AddMessage("\t Successful: " + mxdFile + " " + (mxd_version(mxdFile)) + "\n")
    txtFile.write("\t Successful: " + mxdFile + " " + (mxd_version(mxdFile)) + "\n")
arcpy.AddMessage("------------------All MXDs Completed-------------------")
txtFile.write("------------------All MXDs Completed--------------------")
txtFile.close()
   

Outcomes