Help with arcpy.ListDatasets

1842
4
11-25-2013 05:51 AM
Emilbrundage
New Contributor III
I am simply trying to create a list of all the features within a geodatabase. It seems easy enough, but here is what happens with my script:

>>> import arcpy
>>> from arcpy import env
>>> arcpy.env.workspace = "C:\E1B8\Grid_Create_Update_11-2013\CalcMiles.gdb"
>>> datasetList = arcpy.ListDatasets("*", "Feature")
>>> len(datasetList)
0


My geodatabase contains various features, but as you can see my code creates an empty list. What am I missing?

Thanks!
Tags (2)
0 Kudos
4 Replies
MathewCoyle
Frequent Contributor
Are you looking for ListFeatureClasses?
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Hi Emil,

The arcpy.ListDatasets function will list the feature datasets in your geodatabase.  If you are looking to create a list of all the feature classes in your geodatabase, try the following:

arcpy.env.workspace = "C:\E1B8\Grid_Create_Update_11-2013\CalcMiles.gdb"

fcList = []

#list feature classes in feature datasets
for dataset in arcpy.ListDatasets("*"):
   for fc in arcpy.ListFeatureClasses("*", "", dataset):
      fcList.append(fc)

#list stand alone feature classes
for fc in arcpy.ListFeatureClasses("*"):
   fcList.append(fc)

print fcList
0 Kudos
Emilbrundage
New Contributor III
Ah, I knew it would be something obvious. Thanks for the help guys!
0 Kudos
XanderBakker
Esri Esteemed Contributor
... and if you're wondering why you are not getting any results, then it's because your workspace is not being set correctly:

arcpy.env.workspace = "C:\E1B8\Grid_Create_Update_11-2013\CalcMiles.gdb"


should be:

arcpy.env.workspace = r"C:\E1B8\Grid_Create_Update_11-2013\CalcMiles.gdb"


or

arcpy.env.workspace = "C:/E1B8/Grid_Create_Update_11-2013/CalcMiles.gdb"


Kind regards,

Xander
0 Kudos