Trying to write a script to merge feature classes based off their name. Steps are as follows -
- In the original geodatabase, find polygon feature classes that end with a particular suffix ( ie *15_AM)
- In a new geodatabase, merge them together based on their names (So Peaks_15_AM, Peaks_14_AM and Peaks_13_AM to Peaks_AM)
I'm a novice and my code is very crude, it works for a single feature class but the loop does not accept a list for the 'Keyword' variable. I know I need to somehow iterate over a list but have been stuck how to approach it.
Ideally if I could use the feature class names without the suffix as the 'Keyword' that would be great, but could also just use some raw strings.
import arcpy
import os
#variables
arcpy.env.workspace = r"D:\Old.gdb"
OutputGDB = "D:\New.gdb"
FCS = set(arcpy.ListFeatureClasses("*15_AM", "polygon") + arcpy.ListFeatureClasses("*14_AM", "polygon") + arcpy.ListFeatureClasses("*13_AM", "polygon"))
Keyword = "Peaks"
fc = []
#merge
for i in FCS:
if Keyword in i:
fc.append(i)
arcpy.Merge_management(fc,OutputGDB+"/"+Keyword+"_AM")