bogdanpalade

Multivalue problem

Discussion created by bogdanpalade on Jun 28, 2011
Hello,
The script below was mainly taken from arcgis help file and will repair data sources (for data moved from initialFolder to finalFolder) within several mxd files (present in folderPath)

import arcpy, os

folderPath = arcpy.GetParametersAsText(0)
initialFolder = arcpy.GetParametersAsText(1)
finalFolder = arcpy.GetParametersAsText(2)
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":
            mxd = arcpy.mapping.MapDocument(fullpath)
            mxd.findAndReplaceWorkspacePaths(initialFolder, finalFolder)
            mxd.save()

del mxd


The script works fine as it is (updating data sources from data that was moved from one folder to another folder) but I thought that would be good to also handle situations where original data located in several folders was moved to other different folders. For that I thought I would use the Multivalue option when setting the script parameters in ArcGIS. Multivalue option needs a loop in the python script in order to work properly.
I updated the script in the following way but as you can guess, it does not work and it does not repair nothing:

import arcpy, os

folderPath = arcpy.GetParametersAsText(0)
initialFolder = arcpy.GetParametersAsText(1).split(";")
finalFolder = arcpy.GetParametersAsText(2).split(";")
for i in initialFolder:
    for y in finalFolder:
        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":
                    mxd = arcpy.mapping.MapDocument(fullpath)
                    mxd.findAndReplaceWorkspacePaths(initialFolder, finalFolder)
                    mxd.save()

del mxd


Does anybody know what might be wrong?

Thanks,

Bogdan

Outcomes