Seven years old but in case anyone is looking for an solution.. I wanted to be able to do this, and the ridiculous data structures created by the map packaging process just didn't cut it for me so I did my normal hacking and chopping of Midalvo's script and came up with the following:
import arcpy, os, datetime
arcpy.env.overwriteOutput = True
folderPath = arcpy.GetParameterAsText(0)
newBasePath = arcpy.GetParameterAsText(1)
OutFGDBName = arcpy.GetParameterAsText(2)
OutFGDBName = OutFGDBName + ".gdb"
newPath = newBasePath # Create new folder for MXD and FGDB
newFGDB = str(newPath)+"\\" +OutFGDBName
if not os.path.isdir(newFGDB):
newFGDB = arcpy.CreateFileGDB_management(newPath, OutFGDBName) # Create new FGDB
newFGDB = str(newFGDB)
#Loop through each MXD file
for root, dirs, files in os.walk(folderPath):
for file in files: # files is a list of files in the current directory
if file.lower().endswith(".mxd"):
dataSourceSet = set() # Keep track of already copied datasources
fullpath = os.path.join(root, file) # root is the current directory
fileName = os.path.splitext(file)[0] # Get filename for new folder name
arcpy.AddMessage("FileName = {}".format(fileName))
#Reference MXD
mxd = arcpy.mapping.MapDocument(fullpath)
DFList = arcpy.mapping.ListDataFrames(mxd)
for df in DFList:
lyrList = arcpy.mapping.ListLayers(mxd, "", df)
arcpy.AddMessage("Fullpath = {}".format(fullpath))
for lyr in lyrList:
lyrName = lyr.name
if lyr.supports("dataSource"):
lyrDatasource = lyr.dataSource
lyrDataSetName = lyr.datasetName
qname, q_extension = os.path.splitext(lyrDatasource)
if q_extension in (".TIF", ".tif",".JPG",".jpg",".png",".PNG",".ECW",".ecw",".sid",".SID",".img",".IMG",".grd",".GRD"):
lyrDataSetName = lyrDataSetName[:-4]
if lyrDataSetName[:1].isdigit():
lyrDataSetName = "y" + lyrDataSetName
lyrDataSetName1= (lyrDataSetName.replace(" ","").replace("?","").replace(",","").replace(chr(33),"").replace("-","").replace(chr(64),"").replace(chr(36),"").replace(chr(42),"").replace(chr(35),"").replace(chr(59),""))
arcpy.AddMessage("lyrName = {}".format(lyrName))
arcpy.AddMessage("lyrDatasource = {}".format(lyrDatasource))
arcpy.AddMessage("newLayername = {}".format(lyrDataSetName1))
destfeature = (str(newFGDB) + "\\" + str(lyrDataSetName1))
arcpy.AddMessage("destLayerfull = " +(destfeature))
if lyrDatasource not in dataSourceSet:# If datasource not already copied, then copy it
arcpy.env.workspace = newFGDB
chkpath = (os.path.join(newFGDB, lyrDataSetName1))
if arcpy.Exists(destfeature) == True:
arcpy.AddMessage("Already exists")
elif arcpy.Exists(chkpath) == False:
arcpy.AddMessage("New Layer")
newLyrPath = arcpy.CopyFeatures_management(lyrDatasource, lyrDataSetName1)
else:
arcpy.AddMessage("None")
lyr.replaceDataSource(newFGDB, "FILEGDB_WORKSPACE", lyrDataSetName1) # Repoint layer datasource to new FGDB
arcpy.AddMessage(newFGDB + " "+ lyrDataSetName1)
dataSourceSet.add(lyrDatasource) # Keep track of datasource name to avoid copying same datasource twice
savefile = str(newPath+"\\"+fileName+".mxd")
arcpy.AddMessage (savefile)
mxd.save() # Save new MXD in new folder
Set this up as a script tool and set the parameters as follows:

I copy my mxd's to a single folder and use that as the input folder.. provide an output folder path and a name for the output gdb. It does very simple data comparisons to avoid duplication. It just looks at the layer name... If you had 2 mxd's that both had a layer named "camps" that were meant to point at different datasets it would only copy the first one as it only looks at filenames to decide if it is duplicate data or not.
Once it is done I run another script on the folder to make the mxds all relative path and zip the whole folder.
import arcpy, os
FileName = []
FolderPath = []
FolderPath = arcpy.GetParameterAsText(0)
for FileName in os.listdir(FolderPath):
FullPath = os.path.join(FolderPath, FileName)
if os.path.isfile(FullPath):
BaseName, extension = os.path.splitext(FullPath)
if extension.lower() == ".mxd":
arcpy.AddMessage(FullPath)
mxd = arcpy.mapping.MapDocument(FullPath)
mxd.relativePaths = True
mxd.save()