I think you should research/ask about writing to a CSV file separately at StackOverflow because the technique you are using to do that is pure Python rather than ArcPy.
For the remainder I think this should work (use a modification of your file geodatabase location where I have used C:\temp\test.gdb):
import arcpy
arcpy.env.workspace = r"C:\temp\test.gdb"
datasetList = arcpy.ListDatasets('*','Feature')
for dataset in datasetList:
# arcpy.env.workspace = dataset
arcpy.env.workspace = r"C:\temp\test.gdb\{0}".format(dataset)
fcList = arcpy.ListFeatureClasses()
for fc in fcList:
print arcpy.env.workspace,fc
The two main issues were:
- using back slashes in your pathname - you need to convert them to double backslashes, change them to forward slashes or simply escape them using the letter r like I have above
- the single quote in your pathname will leave Python looking for the other one to close that string
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
It looks like you are trying to find all map projects and print all layers in each to a csv file?
Try this: