Hi everyone,
I am experiencing an issue with the ListFeatureClasses function in ArcPy. Below you can see that my Fire.gdb geodatabase contains some feature classes which exist in the directory but are not reported by the function. Do you have any suggestions why this could be the case? I would also appreciate if you have any suggestions about how to make them visible again.
Below, I also inserted a code on how these feature classes were generated: They were essentially copied from another feature class.
Thank you,
David
arcpy.env_workspace = Geodatabase
print(Geodatabase)
C:\Users\Administrator\Documents\Fire.gdb
feature_list = arcpy.ListFeatureClasses()
day_name = "PolyFire_2010305_d07"
if day_name in feature_list:
... print(True)
else:
... print(False)
False
alt_path=Geodatabase + "\\" + day_name
desc=arcpy.Describe(alt_path)
desc.dataType
'FeatureClass'
desc.CatalogPath
'C:\\Users\\Administrator\\Documents\\Fire.gdb\\PolyFire_2010305_d07'
Geodatabase_rep = "C:\Users\Administrator\Documents\\Fire rep.gdb"
arcpy.env.workspace = Geodatabase_rep
feature_classes = arcpy.ListFeatureClasses()
for fc in feature_classes:
out_fc = os.path.join(Geodatabase, fc)
arcpy.CopyFeatures_management(fc, out_fc)
print(fc)
I believe ListFeatureClasses only lists standalone feature classes, so if you have feature classes in feature datasets you will need to use arcpy.ListDatasets.
#Print all feature datasets
datasets = arcpy.ListDatasets()
for dataset in datasets:
print(f"\nFeature Classes in Dataset {dataset}:")
fcs_in_dataset = arcpy.ListFeatureClasses(feature_dataset=dataset)
for fc in fcs_in_dataset:
print(fc)
Thank you very much for the reply!
Unfortunately, arcpy.ListDatasets() returns an empty result, i.e. there are no feature datasets in the geodatabase. As you can see at the end of the first picture too, the location of the feature class seems to be the root of the geodatabse.
desc.CatalogPath 'C:\\Users\\Administrator\\Documents\\Fire.gdb\\PolyFire_2010305_d07'
Looks like the below is incorrect
## update this
Geodatabase_rep = "C:\Users\Administrator\Documents\\Fire rep.gdb"
## to this
Geodatabase_rep = "C:\\Users\\Administrator\\Documents\\Fire rep.gdb"
## or this
Geodatabase_rep = r"C:\Users\Administrator\Documents\Fire rep.gdb"
spaces in file paths will inevitably cause problems. Raw encoding as @Clubdebambos shows should be standard practice as well.