ArcPy – How to Move Feature Classes to Feature Dataset in ArcGIS?

arcpyfeature-dataset

I have a File Geodatabase. I am using Python to manipulate data. I have a bunch of Feature Classes in the root of the FGDB. What I need to do is to loop through them and move all of them into a 'Sewers' Dataset. I am able to do so by using ArcCatalog but haven't found a way to programatically to so. The following script generates error: 'Manhole' Feature Class already exists.

fd = "Sewers"
for fc in featureclasses:
arcpy.CopyFeatures_management(fc,target_gdb+"\\"+fd+"\\"+fc)

Best Answer

Instead of CopyFeatures_management, use FeatureClassToGeodatabase_conversion (per this thread: https://community.esri.com/thread/209420-arcpy-move-feature-class-into-feature-dataset).

Pro reference: https://pro.arcgis.com/en/pro-app/tool-reference/conversion/feature-class-to-geodatabase.htm

Desktop reference: http://desktop.arcgis.com/en/arcmap/10.3/tools/conversion-toolbox/feature-class-to-geodatabase.htm

If the name already exists in the output geodatabase, a number will be appended to the end to make the feature class name unique (for example, rivers_1).

You can also control the name of the input feature class manually.

Once you have confirmed the dataset has been imported into the desired feature dataset, you can then remove the original feature class if desired through Delete_management.

Related Question