Is there a way to check if a feature class full path string is a path to a feature class within a file geodatabase feature dataset in arcpy?

For example:


I'd like to return testdataset.

I can't find it in any of the applicable Describe objects. I can do it with string manipulation...

fullpath = r"C:\test\test.gdb\testdataset\featureclass"
pathlen = len(fullpath.split (".gdb")[0]) + 4
namelen = len(fullpath.split ("\\")[-1])
dataset = fullpath[pathlen:-namelen].replace ("\\", "")

This seems like too much code though.

Is there a better way?

  • Why not making these lines of code a reusable function? Mar 13, 2015 at 23:09
  • What is your ultimate goal? For example, are you looking to add this in a conditional statement? `
    – Aaron
    Mar 14, 2015 at 0:43

2 Answers 2


Maybe this:

>>> #testfc is a fc within a fd, as shown with this catalogPath statement:
>>> desc = arcpy.Describe('testfc')
>>> desc.catalogPath
>>> #this shows how to essentially use the Describe method twice to get the fd name:
>>> desc = arcpy.Describe(fc)
>>> if hasattr(desc, 'path'):
...     descPth = arcpy.Describe(desc.path)
...     if hasattr(descPth, 'dataType'):
...         if descPth.dataType == 'FeatureDataset': 
...             print 'the feature dataset name: {0}'.format(descPth.name)
    the feature dataset name: dataset1

Use Describe on the feature class parent directory.

if arcpy.Describe(os.path.dirname(path_to_featureclass)).dataType == 'FeatureDataset': 
    do something...
    do something else...

If you don't have the path already, you can get it with the catalogPath property:


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.