[GIS] arcpy.Delete_management(“”) not working

arcgis-10.1arcpypython

I've written a script in a python toolbox. That script creates a folder in the user defined workspace for all the output files that are created during the script process. When the script is done, I don't need these files anymore because I've saved my results in an extra folder. I want to delete this temporary folder and all of its files and wanted to use the delete_management tool like this:

# Set Workspace
    arcpy.env.workspace = parameters[2].valueAsText

    # Set Temporary Output
    arcpy.CreateFolder_management(arcpy.env.workspace, "Temp")

    # Delete temporary Files
    arcpy.Delete_management("Temp")  

But that clearly doesn't work and it is not even giving me an error message. The delete line just has no effect. What am i doing wrong here?

edit: I'm using ArcGIS 10.1 and the parameters[2] string is the users input.

Best Answer

The problem is that the Delete management task doesn't know what you are trying to delete. You either need to give it the path the to folder or create a variable to hold the path and pass that to delete management.

Try something like this

arcpy.env.workspace = parameters[2].valueAsText
tempfolder = arcpy.CreateFolder_management(arcpy.env.workspace, "Temp")

# Set Temporary Output
#arcpy.CreateFolder_management(arcpy.env.workspace, "Temp")

# Delete temporary Files
arcpy.Delete_management(tempfolder)
Related Question