merge or append features classes based on a part of their names

589
1
01-22-2014 04:44 AM
PaoloPensalfini
New Contributor III
Hi everybody!
I've got ONE file geodatabase with about 400 feature classes (FC). Here attached is a part of that .gdb.
I need to merge that features (or better append one feature - 00 - to the other)  that has got the same name except for the "00".
For example:
"_01P11_line" must be merged with "_01P11_line00"
or better
"_01P11_line00" (input) appended to "_01P11_line" (target)
and, after the merging/appending, delete the "00" feature class.
I was thinking to proceed with an iteration in modelbuilder or/and a python script...
could someone help me, please?
Thanks in advance
Paolo
0 Kudos
1 Reply
AdamMarinelli
Occasional Contributor
This should work for basic scenarios that follow the same syntax as the feature classes in the screenshot you provided:

import arcpy

#Set workspace of your File Geodatabase
arcpy.env.workspace = r'C:\gisworkspace\WORKSPACE\Forums\AppendDuplicate.gdb'

#List all polyline feature classes
featureClasses = arcpy.ListFeatureClasses("", "Polyline")

#Iterate feature class list
#Find the inputs in list (ending in '00') and append them to their target
for fc in featureClasses:
    if fc[-2:] == '00':
        input = fc
        #Remove last two characters to find the target
        target = fc[:-2]
        
        arcpy.Append_management(input, target)
        
        #Uncomment the next line to delete the input feature class
        #arcpy.Delete_management(fc)

print 'Complete'
0 Kudos