I am working on a simple python script that will check for the existence of a
shapefile, remove that
shapefile if it is found, then export an SDE feature class to a
shapefile. The reason for doing it this way, is if the
shapefile already exists, then when the tool exports the feature class to a
shapefile it will add "_1" to the name, and so on.
I am having a problem with the tool when the script identifies that the
shapefile exists in the user-defined folder. If the
shapefile does not exist in the folder, the tool works flawlessly, however, if it does exists, I only end up with a
.shp.XML instead of the actual
Below is the script I am using. I have removed my actual database connection filepath and replaced it with the text "SDE database connection." This script prompts the user to choose an output folder as a parameter before initiating the script.
Why am I only getting the
.shp.XML file extension when the script identifies that the
shapefile already exists in the user-defined folder? Should I be using a different method to check for and delete the old
import arcpy, os # VARIABLES Stormwater_Points = SDE database connection Output_Location = arcpy.GetParameterAsText(0) # REMOVE OLD SHAPEFILE Old_Shapefile = os.path.join(Output_Location, 'Stormwater_Points.shp') if os.path.exists(Old_Shapefile): os.remove(Old_Shapefile) else: arcpy.AddMessage('Old shapefile not found in this directory, exporting new shapefile to selected directory') # EXPORT NEW SHAPEFILE arcpy.FeatureClassToShapefile_conversion(Stormwater_Points, Output_Location) arcpy.AddMessage('Done')