I am looking for a way to check the mxd version of a bunch of mxds. I found a script here at ArcPy method to determine ArcMap document version
I am using ArcGIS 10.3.1 on my desktop.
It goes through the directories and for every mxd it finds it grabs a bunch of details, one of which is the version. My only problem is that sometimes it can not find the version of ArcGIS; it seems to be about 50/50. At first I thought if it didn't return that correct value that meant it was below 10.0. But running my script on 200 mxds it returned the value 9.3 a few times, which means that the ones where it does not return any value could be any version and not just something below 10.0.
The current code taken from the other question:
def getMXDVersion(mxdFile):
matchPattern = re.compile("9.2|9.3|10.0|10.1|10.2|10.3")
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)
#print mxdFile
#print joinedChars
#print regexMatch
if len(regexMatch) > 1:
version = regexMatch[len(regexMatch) - 1]
return version
elif len(regexMatch) == 1:
version = regexMatch[0]
return version
else:
return 'version could not be determined for ' + mxdFile
Is there any other way to find the map document's version number?
Best Answer
What you are after may not be determinable, it requires that the document info was saved/embedded and as you've found that is not often embedded into the document. I cannot find any reference to when this data is saved/skipped. For what it's worth this is another method:
This uses COM types and the IMapDocument.GetVersionInfo interface in python; as I have discovered only about half of my map documents have this metadata attached to them. This however does expose another interface IMapDocument.DocumentVersion which, when it returns a value of 0 means the MapDocument can be opened and 1 or 2 if it can't.. at least you can decide if the MXD can be opened with the current version of ArcMap (value=0) or is a future version (value=1) or the MXD is likely to be broken (value=2).