Trying to merge shapefiles:


def get_folder(fn, k=-2):
    return os.path.split(fn)[0].split(os.sep)[k]


d = defaultdict(list)
with open(fi +'//' + 'exports' + '//'+'info.txt', 'w') as fw:
    for root, dirs, files in os.walk(fi):
        for shapefile in files:
            if shapefile.endswith('.shp'):
                arcpy.AddField_management(os.path.join(root,shapefile), "field_Tmp", "LONG")
                with arcpy.da.UpdateCursor(os.path.join(root,shapefile),'field_Tmp') as cursor:
                    for row in cursor:
                        row[0] = get_folder(os.path.join(root,shapefile))                   

for cat, lst in d.items():

ERROR 000732: Dataset ad1.shp does not exist or is not supported

Although it exists.

This is because it needs to do the merge 'by name'.

The list now is like this:


So it has to merge:

'C:\\Users\\user\\Desktop\\shape\\430\\ad1\\ad1.shp' with


 'C:\\Users\\user\\Desktop\\shape\\430\\ad2\\ad2.shp', with

I think this is the cause of the error.

Can you suggest a fix?

closed as unclear what you're asking by PolyGeo Dec 6 at 20:32

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Do it the way you were trying to in your previous question, using collections.defaultdict(list) with shapename as key and full path+name as values. Or with shapeType as key (using Describe if you want to merge all points together, all lines etc.) – BERA Dec 6 at 14:51
  • I want by name as it said. Tried what I have in the updated above with dict and says ` 000468: Input shape types are not equal ` – user10680652 Dec 6 at 15:00
  • I improved the merge part since it is a dictionary but it still doesn't work. – user10680652 Dec 6 at 15:10
  • Check your shape types - is one polygon, while the other is line, for example? You can't merge disparate types together, so as BERA indicated you can use things like shapeType to programmatically check. – smiller Dec 6 at 15:14
  • They are the same thing they even have the same name just for different areas.Check the last update. – user10680652 Dec 6 at 15:17

Browse other questions tagged or ask your own question.