0

I'm trying to write a basic script that will take all the feature classes in every feature dataset in an enterprise geodatabase and copy to a file geodatabase.

    import arcpy
    from arcpy import env
    env.overwriteOutput=True
    env.workspace="Z:\GIS_Interns\SKadri_2022\scripts\script_test\itsql06.sde"
    arcpy.CreateFileGDB_management("Z:\GIS_Interns\SKadri_2022\scripts\script_test", "bool.gdb")
    fdlist=arcpy.ListDatasets()

    for fd in fdlist:
        fclist=arcpy.ListFeatureClasses()
        for fc in fclist: 
            arcpy.conversion.FeatureClassToGeodatabase(fc, 'Z:\\GIS_Interns\\SKadri_2022\\scripts\\script_test\\bool.gdb')

What ends up happening is that the script will copy over feature classes outside of the feature datasets over to the new file gdb, but skips over feature classes in feature datasets. What can I do to make it copy the ones in the feature datasets as well?

1
  • 1
    Try arcpy.ListDatasets("*","Feature")?
    – Hornbydd
    Sep 27, 2022 at 20:23

1 Answer 1

1

Your arcpy.ListFeatureClasses() is not specifying which feature dataset to use. Your for fd loop never uses fd for anything. So it is copying across the feature classes that are not in ANY feature dataset... multiple times - once for each iteration of the loop.

You need to specify to list the feature classes in fd in the for loop. Once you do this, you will then only copy the feature classes that ARE within feature datasets, so before (or after) the loop, you need to also do it the same what that you are already doing it within the loop, but outside of the loop so it is only done once.

Untested, but this is a modification of your code that might work:

    import arcpy
    from arcpy import env
    env.overwriteOutput=True
    env.workspace="Z:\GIS_Interns\SKadri_2022\scripts\script_test\itsql06.sde"
    arcpy.CreateFileGDB_management("Z:\GIS_Interns\SKadri_2022\scripts\script_test", "bool.gdb")

    fclist=arcpy.ListFeatureClasses()
    for fc in fclist: 
        arcpy.conversion.FeatureClassToGeodatabase(fc, 'Z:\\GIS_Interns\\SKadri_2022\\scripts\\script_test\\bool.gdb')

    fdlist=arcpy.ListDatasets()

    for fd in fdlist:
        fclist=arcpy.ListFeatureClasses("*", "All", fd)
        for fc in fclist: 
            arcpy.conversion.FeatureClassToGeodatabase(fc, 'Z:\\GIS_Interns\\SKadri_2022\\scripts\\script_test\\bool.gdb')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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