Hi Jeffery,
Thanks for your reply. This is the script that I am using. I am having mixed success. Script fails sometimes, giving some Utility.py error.
I would appreciate any suggestions.
Thanks
Jay
import arcpy, datetime, os, io, sys
try:
#Read input parameters from GP dialog
# Prod Setting...
folderPath = arcpy.GetParameterAsText(0)
output = arcpy.GetParameterAsText(1)
sourceString = r"P:\Local" # arcpy.GetParameterAsText(1)
replacmentString = r"\\hq\share" # arcpy.GetParameterAsText(2)
#Create an output file
outFile = open(output, "w")
#Loop through each "LYR" file
count = 0
for path, dires, files in os.walk(folderPath):
for filename in files:
fullpath = os.path.join(path, filename)
if os.path.isfile(fullpath):
if filename.lower().endswith(".lyr"):
groupLayerName = ""
layerFile = arcpy.mapping.Layer(fullpath)
#Reference each layer in a layer file
count = 1
for lyr in arcpy.mapping.ListLayers(layerFile):
if lyr.isGroupLayer:
groupLayerName = lyr.name
if lyr.supports("DATASOURCE"):
oldLoc = sourceString
newLoc = replacmentString
if lyr.dataSource.find(oldLoc) != -1:
ds = lyr.dataSource.replace(oldLoc, newLoc)
index = ds.find(lyr.datasetName)
newds = ds[0:index-1]
if lyr.dataSource.find(".shp") >= 0:
lyr.replaceDataSource(newds, 'SHAPEFILE_WORKSPACE', lyr.datasetName)
outFile.write(fullpath + "\t" + "SHP" + "\t" + lyr.longName + "\t" + groupLayerName + "\t" +lyr.name + "\t" + lyr.datasetName + "\t" + str(newds) + "\t" + "SHP" "\n")
elif lyr.dataSource.find(".mdb") >= 0:
lyr.replaceDataSource(newds, 'ACCESS_WORKSPACE', lyr.datasetName)
outFile.write(fullpath + "\t" + "PGDB" + "\t" + lyr.longName + "\t" + groupLayerName + "\t" +lyr.name + "\t" + lyr.datasetName + "\t" + str(newds) + "\t" + "PGDB" "\n")
elif lyr.dataSource.find(".gdb") >= 0:
lyr.replaceDataSource(newds, 'FILEGDB_WORKSPACE', lyr.datasetName)
outFile.write(fullpath + "\t" + "FGDB" + "\t" + lyr.longName + "\t" + groupLayerName + "\t" +lyr.name + "\t" + lyr.datasetName + "\t" + str(newds) + "\t" + "FGDB" "\n")
layerFile.save()
del layerFile
outFile.close()
#Open the resulting text file
os.startfile(output)
#Delete variables that reference data on disk
del outFile
except Exception, e:
import traceback
map(arcpy.AddError, traceback.format_exc().split("\n"))
arcpy.AddError(str(e))