Thank you, Harles. I did get the code to work somewhat (added +"/Export/" after every dir+"/") but apparently there are some limitations to field entries... That is disappointing. It starts OK, and this is the error I get at the end:Start Time: Wed Jan 26 12:01:16 2011ERROR 000278: Failed on input OID 31, could not write value â??22.5degelbowâ?? to output field Feat_CodeFailed to execute (Merge).Failed at Wed Jan 26 12:01:24 2011 (Elapsed Time: 8.00 seconds) *** ERROR: Shapefiles (Point) failed to merge *** Here is the code that somewhat works:
# This script will merge all point shapefiles in subfolders
# of the workspace specified below
# Import modules and create the geoprocessor object
try:
# 9.2 and beyond
import arcgisscripting, collections, arcpy, sys, os
gp = arcgisscripting.create()
except:
# 9.1 and before
import win32com.client, collections, arcpy, sys, os
gp = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")
# Set version
gp.SetProduct("ArcEditor")
# Set the workspace
gp.workspace = ("C:/Trimble Geomatics Office/Projects")
# Start a blank list for Polygon files
# polyList = []
# Start a blank list for Point files
pointList = []
# For each subdirectory
for dir in os.listdir(gp.workspace):
if os.path.isdir(gp.workspace+"/"+dir+"/Export/"):
# Get a list of the files in each directory
files = os.listdir(gp.workspace+"/"+dir+"/Export/")
# For each file in a given directory
for file in files:
# Get only files that end with .shp
if (file.endswith(".shp")):
print file
# Describe feature class
desc = gp.Describe(gp.workspace+"/"+dir+"/"+"/Export/"+file)
type = desc.ShapeType
#print dir+"/"+file + " type is: " + type
#if type == "Polygon":
# print dir+"/"+file + " is Polygon"
# polyPath = polyList.append(dir+"/"+file)
if type == "Point":
print dir+"/"+file + " is Point"
pointPath = pointList.append(dir+"/"+"/Export/"+file)
# Hard-code the output merged shapefile names
# polyshapefile = "Mergedpoly.shp"
pointshapefile = "Mergedpoint2.shp"
# Given a list of shapefiles, separate each by a ";"
# and put quotes around the whole thing
# def polyshpList(polyPath):
# return '"%s"' % ';'.join(polyList)
def pointshpList(pointPath):
return '"%s"' % ';'.join(pointList)
# Set the variable to the newly formatted list of shapefiles
# polymergedlist = polyshpList(polyPath)
pointmergedlist = pointshpList(pointPath)
# Polygons
# try:
# print "\nMerging " + polymergedlist + " to get " + polyshapefile + "...\n"
# gp.merge_management(polymergedlist, polyshapefile)
#print gp.getMessages()
#except:
# print gp.getMessages()
# print "\n *** ERROR: Shapefiles (Polygon) failed to merge *** \n"
# Points
try:
print "\nMerging " + pointmergedlist + " to get " + pointshapefile + "...\n"
gp.merge_management(pointmergedlist, pointshapefile)
print gp.getMessages()
except:
print gp.getMessages()
print "\n *** ERROR: Shapefiles (Point) failed to merge *** \n"
print "\nDone."