Select to view content in your preferred language

Error with Merge Management when using arcpy.da.Walk

5733
12
Jump to solution
09-04-2014 09:33 AM
IanMurray
Frequent Contributor

Hey all,

I had a goal of making a single shapefile from all the shapefiles I had in a directory, (I have 800 or so), since its hard to share all 800 with someone at once.  I wrote up the following script that I hoped would take care of it using the Merge Tool.


import arcpy
import os
workspace = r"myworkspace"
feature_classes = []
for dirpath, dirnames, filenames in arcpy.da.Walk(workspace,datatype="FeatureClass", type="Polygon"):
    for filename in filenames:
        if filename.endswith(".shp"):
            feature_classes.append(os.path.join(dirpath, filename))
            print filename
print feature_classes


arcpy.Merge_management(feature_classes, r"C:/Data/test.shp")

However, I keep getting the  following error.

ExecuteError: Failed to execute. Parameters are not valid.

Merge only takes 3 parameters, so I am failing to see the issue.

0 Kudos
12 Replies
JamesCrandall
MVP Frequent Contributor

You can also try to output a File Geodatabase Feature Class instead of a .shp and just make an additional conversion step in your process to convert it to a final .shp --- this may take care of issues like you have run into.  There's quite a few issues I've run into that worked themselves out because I moved to an FGDB.

0 Kudos
IanMurray
Frequent Contributor

Thats actually what I did, not that I think it had any bearing on the script working.

Thanks again James

DaveBarrett
Occasional Contributor

Just as an add on to this you should consider merging the shape files into a feature class as I have run into problems where the file size limit for the DBFwas exceeded when merging a large number of polygons. this caused the merge tool to fail but just gave the 999998 or 999999 error code

Dave

0 Kudos