I've written a script in Python that takes in two ascii files that represent surfaces, then convert them to Rasters, and finally Negate their values (i.e. multiply all cells by -1). In the script, I create a temporary folder to store intermediate data and I'd like to delete it after the script has ran, however arcpy.Delete_management does not work. My code is as follows:
import os, arcpy from arcpy.sa import * inputInterp = arcpy.GetParameterAsText(0) inputDiff = arcpy.GetParameterAsText(1) outputDir = arcpy.GetParameterAsText(2) #Ascii to Raster Conversion, store output in temp location arcpy.env.overwriteOutput = True arcpy.env.workspace = outputDir tempFolder = outputDir + os.path.sep + "pyOut" arcpy.CreateFolder_management(arcpy.env.workspace, "pyOut") outInterp = tempFolder + os.path.sep + "Interp_Rast" outDiff = tempFolder + os.path.sep + "Diff_Rast" dtype = "FLOAT" arcpy.ASCIIToRaster_conversion(inputInterp, outInterp, dtype) arcpy.ASCIIToRaster_conversion(inputDiff, outDiff, dtype) #Reversing the rasters to their original values outIntNegate = Negate(outInterp) outDiffNegate = Negate(outDiff) #Cleanup arcpy.Delete_management(tempFolder)
Now here's the part I do not understand. If I add:
Then tempFolder gets deleted as expected. I plan on expanding this script after I get this part working and I really do not want to delete every individual temporary variable I create. I suspect this has something to do with the workspace but I couldn't find any solutions after browsing similar posts. Any ideas?