This approach uses the Walk
function in the arcpy site package to recursively find and gather feature classes from a directory. Once a list of feature classes is generated, it merges the featureclasses.
import arcpy
import os
# Define the workspace where all the file geodatabases are located
workspace = r'C:\temp'
# Define the path of the output merged feature class
merged_fc = r'C:\path\to\some\file_geodatabase.gdb\merged'
# Create an empty list to populate with feature classes
fcs = []
# Walk through the directory topdown and search for all featureclasses
walk = arcpy.da.Walk(workspace, topdown=True, datatype="FeatureClass")
for dirpath, dirnames, filenames in walk:
for filename in filenames:
# Append the feature class to the fcs list
fcs.append(os.path.join(dirpath, filename))
# Merge the list of feature classes
arcpy.Merge_management(fcs, merged_fc)