Hi,
I have a list of geodatabase feature class names and I would like to have the dataset names for each if any.
Ideally I would prefer not to loop over each element of the geodatabase to find it. I was hoping arcpy.Describe would contain that information, but no.
import os, arcpy
workspace = "path/to/geodatabase.gdb"
fc_list = ["fc_1_name", "fc_2_name", "fc_3_name"]
for fc in fc_list:
desc = arcpy.Describe(os.path.join(workspace, fc))
print(desc.catalogPath) #does not includes dataset if any
Any suggestion would be appreciated!
Thanks
Solved! Go to Solution.
ok thank you, but as I said in the post, I just have the featureClass names, not the path with the dataset. Of course, if I did have the complete path, I could use pathlib or os.path to retreive the dataset from it.
You're right, I misread your post and thought you needed to extract the dataset from the featureclass you already had.
As Alfred showed you need to mess with the environment and dataset to get a mapping with just a gdb path.
I have a wrapper class I use for this documented in this blog post if that's something that would interest you.
It turns the confusing and tedious process of mutating the environment into something that's more modular.
If you already have the file paths for the feature class then you can simply use o.path.split(filepath)[0] to get the dataset. Datasets are generally treated like subfolder in gdbs and sdes. You can check if the file path is a dataset vs an .sde or .gdb by simply checking if those exists at the end of the file path.