thanks Kristya
Saldy iam now getting an error on Line 4:
'Parsing error <type 'exceptions.SyntaxError'>: invalid syntax (line 4)'
i take this to be ' gp.workspace = ("C:\LINZ_Topo_Data\South_island\")' where all my subfolder are stored...
where you get the same problem?
gp.workspace = "C:\\LINZ_Topo_Data\\South_island\\"
gp.workspace = r"C:\LINZ_Topo_Data\South_island\"
Eric, I don't see an option to "execute code from the clipboard" when I right click in the interactive window. See attached .jpg...
What version of PythonWin are you using? I have v2.5 (build 210).
P.S. Yes I realize this topic was hijacked... Sorry.
# 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 = ("W:\GPS\Trimble_Jobs\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):
# Get a list of the files in each directory
files = os.listdir(gp.workspace+"/"+dir)
# 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+"/"+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+"/"+file)
# Hard-code the output merged shapefile names
# polyshapefile = "Mergedpoly.shp"
pointshapefile = "Mergedpoint.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."
if type == "Point": print dir+"/"+file + " is Point" pointPath = pointList.append(dir+"/"+file)
# 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."