Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

How to merge Shapefiles from multiple folders into Geodatabase Featureclass?

$
0
0

I have a question regarding the merge of a lot of folders, which has a lot subfolders, which has the shapefiles stored. I would like to merge all those in one geodatabase.
So I thought to use a Python script.

import os, arcpy.da

print os.getcwd()

for dirname, dirnames, filenames in os.walk('.'):
    for subdirname in dirnames:
        current_dir =  os.path.join(dirname, subdirname)
        arcpy.env.workspace = current_dir
        fcList = arcpy.ListFeatureClasses(".shp")
        Merge = r"D:TestMerge_multiple.gdbTotals"
        for fc in fcList:
            print fc
            arcpy.Merge_management([fc,destination],Merge)
            arcpy.Delete_management(desination)
            arcpy.Rename_management(Merge, destination)
        break

So, I started the script and after a minute it stops and unfortunately, no result. Because there are several different names in the shapefiles, I thought to use only the suffix .shp.

Could you help me?

[Edit]
I get the path of the working directory in the python window. After this message, the window closes without any errors.
enter image description here

[Edit2]
Based on PolyGeo’s advice, I’ve run the script also in the IDLE environment and this is the result:

enter image description here


Viewing all articles
Browse latest Browse all 767

Trending Articles