The trick you're missing is making each gdb the active workspace before listing the contents:
for item in workspaces:
print item
env.workspace = item
fcs = arcpy.ListFeatureClasses()
for fc in fcs:
print '\t', fc
Also note that this will miss an feature classes inside feature datasets, see Listing all feature classes in File Geodatabase, including within feature datasets? to solve that.
More generally, if you use r
you don't need to double backslash everything (makes for easier copy and paste from windows explorer address bar etc.): e.g. r'D:\output'
It seems as you cannot use this shortcut any longer. When the Database Connections
special folder is dragged into the Python window in ArcMap, you get:
r'C:\Users\%username%\AppData\Roaming\ESRI\Desktop10.4\ArcCatalog\'
This is because there is only one Database Connections
per user, that is it is a universal source of all your enterprise database connections.
However, in ArcGIS Pro, Databases
is specific to a project, that is every project will have its own Databases
shortcut. When you drag the Databases
into the Python window, you get:
"GDB"
There is no data path to the actual folder where the .sde files are stored. Thus, you won't be able to supply the Databases shortcut when running your arcpy
scripts targeting ArcGIS Pro.
Trying to supply:
r"GDB\db.sde\esrigdb.DBO.DataLines"
or r"Databases\db.sde\esrigdb.DBO.DataLines"
just won't work.
Since you are always working with a specific ArcGIS Pro project, I'd get its homeFolder
and then use os.path.join
to get the database path:
proj = mp.ArcGISProject(r"C:\Users\%username%\Documents\ArcGIS\Projects\MyProject\MyProject.aprx")
print(proj.homeFolder)
C:\Users\%username%\Documents\ArcGIS\Projects\MyProject
The .sde connection files are stored in the project homeFolder
.
arcpy.Describe(os.path.join(proj.homeFolder,'spatial_db.sde','esrigdb.DBO.DataLines')).shapeType
'Polyline'
Best Answer
Replace
print(layer)
withprint(layer.dataSource)