Collapsing folder structure into single folder using ArcGIS ModelBuilder?

Looks like you have found a bug in ModelBuilder, but fortunately there is a solution!

In your master model insert a calculate value tool, Workspace is a precondition to it. In the Calculate tool type the expression as shown below and make sure output data type is set to folder. You can then connect that to your sub-model, so it all works.

Using Calculate Value to change data type


I created what I believe to be the functioning standalone python script to do this. Here is the test file structure I created:

Testing folder structure

Here is the python script to copy each FGDB from the parent and subsequent folders C:\Folder1 to another directory I created called C:\Folder1Copy

import arcpy
import os

#Set parent directory
arcpy.env.workspace = r'C:\Folder1'

#List the subfolders in the parent directory 
workspaces = arcpy.ListWorkspaces("*", "Folder")

for workspace in workspaces:
    #Set new environment to list workspaces
    arcpy.env.workspace = workspace
    fgdbs = arcpy.ListWorkspaces("*", "FileGDB")

    #Iterate through each FileGDB contained within and copy to destination 
    for fgdb in fgdbs:
        #parsing the name from the full path of each FGDB
        #name = os.path.basename(fgdb).rstrip(os.path.splitext(fgdb)[1])
        name = os.path.basename(fgdb)[:-4]
        arcpy.Copy_management(fgdb, "C:/Folder1Copy/{0}.gdb".format(name))

Here was the final output:

Copied FGDBs in new directory