I have an ArcMap Python Toolbox where one input parameter is of datatype DEFolder.
When I select an existing folder for this parameter and when the tool fails, the existing folder is deleted. I think this is not desirable, since one can accidentally destroy a lot of data this way.
Is there a way to prevent this from happening? It would be nice to be able to e.g. overwrite output from previous tool execution but prevent deletion of the output folder in case of errors.
I am using ArcMap 10.8.
Here is a MWE Toolbox that reproduces the issue:
 
import arcpy as ap
class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "Toolbox"
        self.alias = ""
        # List of tool classes associated with this toolbox
        self.tools = [Tool]
class Tool(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Tool"
        self.description = ""
        self.canRunInBackground = False
    def getParameterInfo(self):
        """Define parameter definitions"""
        folder = ap.Parameter(
            displayName = "Output directory",
            name = "Table",
            datatype = "DEFolder",
            parameterType = "Required",
            direction = "Output")
        params = [folder]
        return params
    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True
    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return
    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        return
    def execute(self, parameters, messages):
        """The source code of the tool."""
        n = 5 / 0
        return