Help with Python -->Merge_management

09-19-2011 07:08 PM
New Contributor
I have been working on a Python script that will go into multiple sub folders of the main folder and puts all the files with the same name in a list, and then merge them together. Everything works until the Merge_management tool, i get the following error:

Traceback (most recent call last):
File "H:\Python\Practice\Sidra Scripts\", line 31, in <module>
arcpy.Merge_management(fencePoList, outputName)
File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\", line 3124, in Merge
raise e
ExecuteError: Failed to execute. Parameters are not valid.

The script is:

import arcpy
import os
from arcpy import env
arcpy.overwriteoutput = 1

inputFolder= "H:\\Python\\Practice\\SampleData\\\Survey_data"
targetFileName= "H:\\Python\\Practice\\SampleData\\Survey_data\\Merged_Posts.shp"
# Create the empty list
fencePoList= []

for root, dirs, files in os.walk(inputFolder, topdown=True):
for filename in files:
if filename[-6]=="P":
#print os.path.join(root, filename)
fencePosts = str(os.path.join(root, filename))

# Format the list of shapefiles properly for the merge tool
#mergeSHP = '"'+';'.join(fencePoList)+'"'
#print mergeSHP

# Determine the new output feature class path and name
outputName = os.path.join(inputFolder, "Merged_Posts.shp")
#Merging the fence_pole files in all the folders
print "starting merge"
arcpy.Merge_management(fencePoList, outputName)
print "ending merge"


#except Exception, ErrorDesc:
#If an error set output boolean parameter "Error" to True.
# arcpy.AddError(str(ErrorDesc))
# row = None
# rows = None

Hope someone can help!
0 Kudos
1 Reply
New Contributor
I checked my code and i figured out the problem list should only have .shp files, ive modifed my code and its working now :)))
0 Kudos