I developed this kludge to parse version numbers from MXD documents. It basically reads the first 4000 or so characters of an MXD document and searches for a version number. I tested with MXD versions 9.2, 9.3, 10.0, and 10.1.
import re
def getMXDVersion(mxdFile):
matchPattern = re.compile("9.2|9.3|10.0|10.1|10.2")
with open(mxdFile, 'rb') as mxd:
fileContents = mxd.read().decode('latin1')[1000:4500]
removedChars = [x for x in fileContents if x not in [u'\xff',u'\x00',u'\x01',u'\t']]
joinedChars = ''.join(removedChars)
regexMatch = re.findall(matchPattern, joinedChars)
if len(regexMatch) > 0:
version = regexMatch[0]
return version
else:
return 'version could not be determined for ' + mxdFile
Here is an example of scanning a folder for mxd files and printing the version and names
import os
import glob
folder = r'C:\Users\Administrator\Desktop\mxd_examples'
mxdFiles = glob.glob(os.path.join(folder, '*.mxd'))
for mxdFile in mxdFiles:
fileName = os.path.basename(mxdFile)
version = getMXDVersion(mxdFile)
print version, fileName
Which returns this:
>>>
10.0 Arch_Cape_DRG.mxd
9.2 class_exercise.mxd
9.3 colored_relief2.mxd
10.1 CountyIcons.mxd
10.0 DEM_Template.mxd
9.2 ex_2.mxd
10.0 nairobimap.mxd
10.0 slope_script_example.mxd
10.1 TrailMapTemplateBetter.mxd
10.0 Wickiup_Mountain_DEM.mxd
>>>