I'm pretty new to python and I have some trouble getting this snippet of code to work. I have some lines that work to copy shapefiles and feature classes, but I haven't managed to be able to copy feature classes from a feature dataset.
A "lookup table" exists with info on the source path, source name, target path, target name, etc. There's a field called 'BatchID' that is used as a reference for what the user wants to be copied. That said, there's a raw input that is in the code and once the user enters the number, the data in that row(s) is copied. I keep getting the error:
ERROR 000732: Input Features: Dataset C:...file path here...\test1.gdb\SanTest does not exist or is not supported Failed to execute (CopyFeatures).
Copy Feature dataset- features
if batch_id == int(btch_num):
ds = arcpy.ListFeatureClasses('','', source_name)
for fc in ds:
print ('These features') + (fc) + (' are in the feature dataset!')
arcpy.CopyFeatures_management(fc, os.path.join(target_path, os.path.splitext(fc)[0]))
3 Answers 3
I used this example in class the other night, it may offer a clue, as it works, basically copies fc out of a dataset, into a folder as shapefiles:
import arcpy
arcpy.env.workspace = "E:/class_5/ForExercise.gdb"
out = "E:/class_5/shp/"
datasets = arcpy.ListDatasets("*", "Feature")
for i in datasets:
print i +" DataSet Name"
fclist = arcpy.ListFeatureClasses('*', "ALL", i)
for x in fclist:
print x +" fc in Dataset"
arcpy.CopyFeatures_management(x, out + x)
print "Done"
Your error shows a path of ..\test1.gdb\SanTest with the slashes wrong unless you used the "r" in-front of the path. Better yet just flip the slashes on your source.
(fc, os.path.join(target_path, os.path.splitext(fc)[0])) The splitext(fc)[0} is how you remove the .shp off of a shapeFile. The fc in the database probably already has this removed. Another option to define the output is path + os.sep + fc
As has been my experience, and also as documented by ESRI, this is often (but not always) due to issues with formatting of paths. You may want to examine what the path in your code os.path.join(target_path, os.path.splitext(fc)[0])
would print out to a string as.
ESRI indicates that the most common causes of this error are:
- Using backslashes instead of forward slashes
- Misspelled folder names
- Having spaces in path names
Source: https://support.esri.com/en/technical-article/000010149
If the File Geodatabase is created with ArcGIS Pro and attribute rules are in place, the feature classes are not readable with Arcmap's arcpy and the ERROR 000732 is occurring.
Explore related questions
See similar questions with these tags.
try
/except
statements in your code snippet because they can mask error messages that might otherwise be helpful. What is the full error message including line number that you get when running the exact code that you have presented?import arcpy
.print ds
?