run python script from custom toolbox

Discussion created by bogdanpalade on Jun 20, 2011
Latest reply on Jun 20, 2011 by bogdanpalade

I am trying to add a script to a toolbox in order to run it more confortably. The script will repair data sources (for data moved from initialFolder to finalFolder) within several mxd files (present in folderPath) and is mainly a copy from the ArcGis help file. I will list it here:

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)

del mxd

The problem is that while it runs perfectly as python script with python idle, it would not run as a script in arcgis toolbox.
I added the script to a new toolbox and I defined the parameters as is follows:

folderPath = folder type, input
initialFolder = folder type, input
finalFolder = folder type, input.

I also tried replacing the folder type with workspace type but still does not work.

when I run the script I get the error: "Error in executing cmd.exe "path to the script. ...Failed to execute script".

Do you know what may be the problem?

Thank you very much,