ArcPy – How to Fix arcpy.Delete_management Not Working

arcpyattributeerrordeleteerror-000258tkinter

I've updated the code with the suggestions in the code but still not working.

arcpy.env.workspace = r'F:\EGM722 - Customising GIS apps\Assignment\folklore.gdb'
arcpy.env.overwriteOutput = True
arcpy.Delete_management('folklore_shape.shp')
#arcpy.Delete_management(r'F:\EGM722 - Customising GIS apps\Assignment\folklore_shape.shp')
arcpy.MakeXYEventLayer_management('Folklore', 'x_coord', 'y_coord', 'folklore_Layer', "PROJCS['IRENET95_Irish_Transverse_Mercator',GEOGCS['GCS_IRENET95',DATUM['D_IRENET95',SPHEROID['GRS_1980',6378137.0,298.257222101]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Transverse_Mercator'],PARAMETER['False_Easting',600000.0],PARAMETER['False_Northing',750000.0],PARAMETER['Central_Meridian',-8.0],PARAMETER['Scale_Factor',0.99982],PARAMETER['Latitude_Of_Origin',53.5],UNIT['Meter',1.0]];-5022200 -15179500 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision", '#')
arcpy.FeatureClassToFeatureClass_conversion("folklore_Layer", "F:\EGM722 - Customising GIS apps\Assignment", "Folkore_shape.shp")

I've tried arcpy.Delete_management('folklore_shape.shp') and arcpy.Delete_management(r'F:\EGM722 – Customising GIS apps\Assignment\folklore_shape.shp')

Getting error;

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Python27\ArcGIS10.5\lib\lib-tk\Tkinter.py", line 1542, in __call__
    return self.func(*args)
  File "F:\EGM722 - Customising GIS apps\Assignment\folklore - 22-04-18 - diff_folder.py", line 132, in new_record
    arcpy.FeatureClassToFeatureClass_conversion("folklore_Layer", "F:\EGM722 - Customising GIS apps\Assignment", "Folkore_shape.shp")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\conversion.py", line 1891, in FeatureClassToFeatureClass
    raise e
ExecuteError: ERROR 000258: Output F:\EGM722 - Customising GIS apps\Assignment\Folkore_shape.shp already exists
Failed to execute (FeatureClassToFeatureClass).

Creating the event layer works it is the delete part that isn't working.

Best Answer

You have a typo in this part of your code:

if arcpy.Exists(r'F:\MyProject\Assignment\folkore_shp.shp'):
   arcpy.Delete_management(r'F:\MyProject\Assignment\folkore_shp.shp')

folklore is misspelled.

Fix:

if arcpy.Exists(r'F:\MyProject\Assignment\folklore_shp.shp'):
   arcpy.Delete_management(r'F:\MyProject\Assignment\folklore_shp.shp')

Also, as commented:

arcpy.env.overwriteOutput = True

And don't forget your raw string for folder paths (or anything with a backslash):

arcpy.FeatureClassToFeatureClass_conversion("folklore_Layer", r"F:\MyProject\Assignment", "folklore_shp")