Find and Replace Workspace Paths- single path works, but multiple paths fails

346
2
Jump to solution
04-13-2012 08:57 AM
847396730
Occasional Contributor III
Hello!  The first script works; it finds all data sourced to the first path and changes it to the second path.  The second script is my attempt to search for multiple paths, and change them all to a different path.  The second script fails, and I can't figure out why.  Thanks for looking!

SCRIPT #1
import arcpy, os
folderPath = r"U:\ServerMigration"
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(r"F:\ServerMigrationTest\Geodatabases", r"U:\ServerMigration\Geodatabases")
            mxd.save()
del mxd

SCRIPT #2
import arcpy, os
folderPath = r"U:\ServerMigration"
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(r"\\datsrva\017GisData", r"F:\ServerMigrationTest\Geodatabases")
            mxd.findAndReplaceWorkspacePaths(r"\\Gissrv1\017gisdatt\017GISDATA", r"F:\ServerMigrationTest\Geodatabases")
            mxd.findAndReplaceWorkspacePaths(r"\\datsrv1\017GisData", r"F:\ServerMigrationTest\Geodatabases")
            mxd.findAndReplaceWorkspacePaths(r"Z:", r"F:\ServerMigrationTest\Geodatabases")
            mxd.findAndReplaceWorkspacePaths(r"\\gissrv1\017GisData", r"F:\ServerMigrationTest\Geodatabases")

            mxd.save()
del mxd
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
847396730
Occasional Contributor III
Well, I'm not certain anyone could have figured this one out without seeing my entire file structure.  The answer is: when describing the existing data source path, you must include the path all the way down to the last folder which contains the database.  Now I am on a journey to write a script that will omit this restriction; if need be, I will generate another post specific to that need.
Thank you!

View solution in original post

0 Kudos
2 Replies
847396730
Occasional Contributor III
Well, I'm not certain anyone could have figured this one out without seeing my entire file structure.  The answer is: when describing the existing data source path, you must include the path all the way down to the last folder which contains the database.  Now I am on a journey to write a script that will omit this restriction; if need be, I will generate another post specific to that need.
Thank you!
0 Kudos
JeffBarrette
Esri Regular Contributor
There should be no such restriction with findAndReplaceWorkspacePaths.  You could replace "C:\" with "D:\" and not have to specifiy the rest of the folder path.  I'm curious what you discover as you dig into it a bit futher.

Jeff
0 Kudos