[GIS] Getting the name of the mxd using python

arcgis-10.1arcgis-desktoparcpypython

I have a python script which reads through all the mxd's in a folder and changes their properties from relative file paths to absolute file paths.

I now want to add a bit to the script to change the version of the mxd from 10.1 to 10.0.

I want the 10.0 mxd to be saved into a pre-defined folder.

The new mxd should have the same name as the original mxd. This is the bit I'm struggling with.

How do I get the name of the original mxd? (defined as basename in the code below).
I'm assuming I need to use an arcpy.mapping function, but I'm completely stumped.

import arcpy, os
#workspace to search for MXDs
Workspace = r"C:\Testing\ImageMapperReplacement\LRM157"
arcpy.env.workspace = Workspace
#list map documents in folder
mxdList = arcpy.ListFiles("*.mxd")
#set relative path setting for each MXD in list.
for file in mxdList:
#set map document to change
filePath = os.path.join(Workspace, file)
mxd = arcpy.mapping.MapDocument(filePath)
#Get the file name
basename = ??????
#set relative paths property
mxd.relativePaths = False
#save map doucment change
mxd.saveACopy (r"C:\Testing\ImageMapperReplacement\LRM157\mxd2\\" + basename + ".mxd", {10.0})

Best Answer

Ok, I've figured it out. Thanks Luke for pointing out that file was already the file name. My other mistake was the brackets around the mxd version number. The final code is as follows.

import arcpy, os
#workspace to search for MXDs
Workspace = r"C:\Testing\ImageMapperReplacement\LRM157"
arcpy.env.workspace = Workspace
#list map documents in folder
mxdList = arcpy.ListFiles("*.mxd")
#set relative path setting for each MXD in list.
for mapdoc in mxdList:
    #set map document to change
    filePath = os.path.join(Workspace, mapdoc)
    mxd = arcpy.mapping.MapDocument(filePath)
    #Get the file name
    basename = mapdoc
    #set relative paths property
    mxd.relativePaths = False
    output = os.path.join(r"C:\Testing\ImageMapperReplacement\LRM157\mxd2", basename)
    #save map doucment change
    mxd.saveACopy (output, '10.0')