This content has been marked as final. Show 4 replies
Below is an example on how to do this. The code adds all the shapefiles first two characters to a list, then removes the duplicates. It will then merge the related shapefiles together to one shapefile.
lstFCs = arcpy.ListFeatureClasses("*") list1 =  # Append first two characters of each shapefile to list for fc in lstFCs: list1.append(fc[0:2]) # Remove duplicates from list list1 = dict.fromkeys(list1) list1 = list1.keys() # Merge feature classes for n in list1: m = str(n) + "*" lstFCs = arcpy.ListFeatureClasses(m) arcpy.Merge_management(lstFCs, n + "_merge")
Thanks for the suggestion, the code below ended up working....kind of. There's over 800 files and the code works like a dream until it gets to the 417th file, then I get a C++ Runtime Error! for Program: pythonw.exe????
Create the Geoprocessor object gp = arcgisscripting.create(9.3) dir = r"C:\temp" output = r"C:\temp\shp" gp.workspace = dir fcs = gp.ListFeatureClasses("*") x = '"%s"' % ';'.join(fcs) print x gp.Append(x, output, "NO_TEST") print gp.getmessages()
Try removing the 417th file and then re-execute the script to see if it works. The file may be corrupted.
I tried that, it's not the problem. I can watch the memory build up, once it gets to a certain threshhold it bombs out????