I'm trying to write script, that looks at the feature classes in a geodatabase and depending on what the feature class ends with, it creates a new dataset in the geodatabase and copies the file into the new dataset. I have 500 feature classes all ending with a value in the range '1 - 22' therefore the script should create 22 datasets and copies all files ending with the same number into its respective dataset. However, I keep getting an ERROR 000210: Failed to execute (CopyFeatures).This is the code I have so far:

import arcpy
import os
arcpy.env.workspace = "C:\Users\Daimon Nurse\Desktop\DFMPROJECT\DFMPROJECT.gdb"
features = arcpy.ListFeatureClasses()
i = 1
while i <= 22:
    out_dataset_path = "C:\Users\Daimon Nurse\Desktop\DFMPROJECT\DFMPROJECT.gdb"
    out_name = "Zone{0}".format(i)
    arcpy.CreateFeatureDataset_management(out_dataset_path, out_name, sr)
    for feature in features:
        outfile = os.path.join(out_dataset_path,out_name)
        if feature.endswith('n{0}'.format(i)):
            outfile1 = os.path.join(outfile,feature)
            arcpy.CopyFeatures_management(feature, outfile1)
    i = i + 1 

del i, outfile, feature, features, out_name, out_dataset_path, inlayer
  • One quick question, are there any relationship classes or feature datasets in the source geodatabase? If there are either of those, it is possible that features you have not explicitly called to be copied have actually been copied over already. I would have to look up the behavior of that specific tool and your specific error code, but I've had an issue similar to what you're describing before and that was the issue. – John Jan 8 '15 at 19:17
  • No there are no relationship classes or datasets as far as I can tell. – Daimon Nurse Jan 8 '15 at 19:22
  • have you tried renaming Daimon Nurse to Daimon_Nurse in your path?Also you cannot have two tables with the same name in a single gdb, so you should change the name of the feature class when you copy it (arcpy.CopyFeatures_management(feature, outfile1 + "b") ) – radouxju Jan 8 '15 at 19:37
  • 6
    You can't have two feature classes with the same name in the same geodatabase, even if one of them is within a feature dataset and another is not. Try appending a suffix using outfile1 = os.path.join(outfile,feature+"_copy") – dmahr Jan 8 '15 at 19:41

I think your first error is right near the beginning.

Instead of:

arcpy.env.workspace = "C:\Users\Daimon Nurse\Desktop\DFMPROJECT\DFMPROJECT.gdb"


arcpy.env.workspace = r"C:\Users\Daimon Nurse\Desktop\DFMPROJECT\DFMPROJECT.gdb"


arcpy.env.workspace = "C:\\Users\\Daimon Nurse\\Desktop\\DFMPROJECT\\DFMPROJECT.gdb"


arcpy.env.workspace = "C:/Users/Daimon Nurse/Desktop/DFMPROJECT/DFMPROJECT.gdb"

Also do the same when setting your out_dataset_path variable.

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.