DirectoryDelete

Description

Deletes on-disk or in-memory directory.

Function syntax

DirectoryDelete(path [, recurse])

History

ColdFusion 9: Added this function

Parameters

Parameter

Description

path

Absolute path of the directory to be deleted. Alternatively, you can specify IP address, as in the following example: DirectoryCreate("//12.3.123.123/c_drive/test"); .

recurse

This is an optional parameter and the default value is false.

If true, the directory and the sub-directories are deleted.

If the directory (being deleted) has sub-directories and you set recurse to false, an exception occurs.

Usage

Ensure that you have the required permissions to run this function.

Example

<h2>DirectoryDelete Example</h2> 
 <h3>Enter a directory to delete.</h3> 
 <form action = "directoryDelete.cfm" method="post"> 
     <label for="delDirectory">Directory Path: </label><input type = "text" id="delDirectory" name = "delDirectory"> 
     <br> 
    <label for="recurse">Recurse: </label><input id="recurse" type="checkbox" value="recurse" name="recurse"> 
    <br> 
     <input type = "submit" value="submit" name = "submit" onclick='return confirm("Are you sure !!!");'> 
 </form> 
 <cfif IsDefined("FORM.delDirectory")> 
     <cfif FORM.delDirectory is not ""> 
     <cfset delDirectory = FORM.delDirectory> 
    <cfset recurse = false> 
    <cfif isDefined("FORM.recurse")> 
        <cfset recurse = true> 
    </cfif> 
         <cftry> 
            <cfset DirectoryDelete(delDirectory,recurse)> 
            <cfoutput><p>Directory <b>#delDirectory#</b> has been deleted.</cfoutput> 
         <cfcatch> 
             <b>Error Message:</b><cfoutput>#cfcatch.message#</cfoutput><br/> 
            <b>Error Detail:</b><cfoutput>#cfcatch.Detail#</cfoutput> 
         </cfcatch> 
        </cftry> 
     </cfif> 
 </cfif>