Search code examples
pythonarcpy

arcpy.CopyFeatures_management error due to bad naming convention


I have a script that downloads a zip file and extracts the shapefile each day. This works fine, but the shapefile is always in the format "polygons.yyyymmdd.shp"

I keep getting errors when trying to copy this file to a geodatabase. I am guessing because there is a period in the shapefile name (no idea why they use this kind of naming structure).

The error is "RuntimeError: Object: Error in executing tool"

shpList = arcpy.ListFeatureClasses()
print shpList
>>>[u'polygons.20150316.shp']

polyFc = "C:\\data\\work.gdb\\" + "polyFc"
arcpy.CopyFeatures_management(shpList, polyFc)

Solution

  • # I renamed using the following:
    for filename in os.listdir("."):
        print filename
        if filename.startswith("polygons"):
            os.rename(filename, "a" + filename[9:])
    
    # To import the shapefile into my geodb I converted the list to string first
    shp = '\n'.join(shpList)
    arcpy.FeatureClassToFeatureClass_conversion(shp, outWorkspace, "polyToday")