#This is the function that will find all the files in the geodatabases and export them into a shapefile
def sdrp_script(statefp):
inworkplace = r'\\path of where you want the files\%s' %statefp
missing_text = open(out_workspace + '/' + str(statefp) + "MissingSDRP.txt","w+") #Creates a Text File that will tell us what is missing
# find all the geodatabases using os.walk
extension = "*.gdb"
all_gdb_files = [file for path, subdir, files in os.walk(inworkplace) for file in glob(os.path.join(path, extension))]
#print all_gdb_files #this actually gets the geodatabases
# read all the feature_classes in the geodatabases
datasetList = []
for dataset in all_gdb_files: # iterate through your list of all_gdb_files.
arcpy.env.workspace = dataset # this dataset is a single gdb from your list of gdbs.
layers = arcpy.ListFeatureClasses('*errors_line', feature_dataset='submission')# this will make an object named layers which will include each feature class from your GDB
for layer in layers: #you need to get a list of layers from the gdb first, then loop through it.
if arcpy.Exists(layer):
datasetList.append(os.path.join(dataset,'submission', layer))
else:
missing_text.write(dataset)
missing_text.close()
print len(datasetList)#checks to see how many there are
# Merge the list of feature classes
arcpy.Merge_management(datasetList, out_workspace + "/" + str(statefp) + "_QC_errors_line.shp")