arcpy.CopyFeatures_management failing

5042
11
02-05-2015 03:19 PM
DanielErklauer
New Contributor III


I am having an issue with using arcpy.CopyFeatures_management.  I am attempting to copy shape files from a temp directory and write them to a database as feature classes.  What is wrong with this code? My print function correctly lists all of the shape files in the temp directory however It then writes one shape to my database directory and gives it the database name.

import arcpy
from arcpy import env
import os
import sys
arcpy.env.overwriteOutput = True
workspace = "S:\\xxx\\GIS\\"
feature_classes = []
walk = arcpy.da.Walk(workspace, datatype="FeatureClass", type="FeatureClass")
outWorkspace = "S:\\xxx\\xxx\\xxx.gdb"
for dirpath, dirnames, filenames in walk:
    for filename in filenames:
        feature_classes.append(os.path.join(dirpath, filename))
print feature_classes
for filename in feature_classes:
    outFeatureClass = os.path.join(outWorkspace, filename.strip(".shp"))
    arcpy.CopyFeatures_management(filename, outWorkspace)
Tags (3)
0 Kudos
11 Replies
DanielErklauer
New Contributor III

@Blake do you have any insight on why my for statements are not working using my the variable?

0 Kudos
BlakeTerhune
MVP Regular Contributor

I apologize Daniel Erklauer‌, I did not read your first post well and was going off what forest knutsen‌ posted. I have not tried testing any of this yet, but you may have to use a conversion (like feature class to feature class) instead of copy features. Or better yet, maybe you could pass your whole list of shapefiles into feature class to getodatabase for a batch load.

0 Kudos