Problem Deleting scratchGDB after script runs

Discussion created by MCusumano on Feb 27, 2014
Latest reply on May 27, 2016 by pcole1
I have a script running that does a bit of spatial analysis, creates a relationship table and exports layout images to JPEG for report.

It runs great, but I am having a problem doing proper cleanup. I go to delete the scratchGDB using arcpy.delete, and it works fine. The problem is that a leftover scratch.gdb remains in the workspace directory.

After running arcpy.delete the leftover scratch.gdb is not a true geodatabase; in ArcCatalog it appears as a folder with a plus to the left of it. Drilling down on the plus and there is nothing in there.

I also added a line to delete that file in python and I get this:

[Error 5] Access is denied: 'D:\\gis\\Data\\scratch.gdb'

Sometimes the script works fine without deleting the scratch.gdb (it simply overwrites), other times it tells me it cannot create the initial output and fails. I would appreciate any help.