Whatever message this page gives is out now! Go check it out!

DirectoryDelete

Last update:
May 18, 2026

Description

Deletes on-disk or in-memory directory.

Category

Function syntax

DirectoryDelete(path [, recurse])

See also

History

ColdFusion (2018 release): Introduced named parameters.
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: {{DirectoryDelete("//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>

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page