3

I have a python script that I am writing to create a copy of a database and then clean it up (basically remove any empty items). Everything is working with the exception of feature classes that are embedded in a feature dataset. I have the portion of code that iterates through these items and is the source of my issue below:

arcpy.env.workspace = inputGDB
dataset_list= arcpy.ListDatasets()

for dataset in dataset_list: 
    featureclass_list=arcpy.ListFeatureClasses("","",dataset)
    for feature in featureclass_list:
        inpath=arcpy.Describe(feature).catalogPath

When I do this, the "catalogPath" returned is not the full path. It only contains the path up to the gdb and then appends the feature class name to it (e.g. it returns D:\Folders\Database.gdb\feature_name not D:\Folders\Database.gdb\Dataset\feature_name). The dataset which this feature was originally in is not returned with the above code. Now if I do:

item=arcpy.Describe(r"D:\Folders\Database.gdb\Dataset\feature_name")
print item.catalogPath

I get the correct path for the data in question. So the question I have is how do I get the full data path for feature classes embedded in a dataset with some option similar the the first snippet of code?

  • os.path.join(inputGDB,dataset,feature). You already have all the information that you need and the os.path.join will smash it all together with your os folder separator so is valid for Unix, Linux, Mac, Windows and any other platform that python is valid on. Make sure you import os before you try to use it... although it's a default lib for python you still have to tell python you want to use its functions. – Michael Stimson Mar 14 '16 at 21:59
  • 1
    I think you should report this bug (that @blah238 seems to have verified) to Esri. Hopefully, they will accept a link to this Q&A as being all the information that they need to reproduce it. – PolyGeo Mar 14 '16 at 23:55
3

Try something like this instead:

arcpy.env.workspace = inputGDB
dataset_list = arcpy.ListDatasets()

for dataset in dataset_list: 
    for child in arcpy.Describe(dataset).children:
        if hasattr(child, 'datasetType') and child.datasetType == 'FeatureClass':
            inpath = child.catalogPath

It seems like a bug that catalogPath is different depending on how you obtain the Describe object reference.

See also: Creating table containing all filenames (and possibly metadata) in File Geodatabase?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.