How To The Write `directoryDelete( path )` Function In ColdFusion?
Description:-
This is used to delete a directory on disk or in memory if you have the required permissions to run this function.
directoryDelete( path );
Attributes:-
path:- This is a required attribute, the path of a directory to be deleted on an absolute on-disk or in-memory location. Alternatively, you can specify the IP address as in the bellow example:directoryCreate( "//192.168.0.1/new_disc/test" );
recurse:- This is a non-required attribute, the default value is falseSet it as true if you want the directory and the sub-directories to be deleted. If the directory(being deleted) has sub-directories and you set recurse to false, an exception occurs.
Example:-
In this example, we will delete this d:\files\documents directory and then check if this exists or not.
<cfscript>
if ( !directoryExists( "d:\files\documents" ) ){
directoryCreate( "d:\files\documents" );
}
writeOutput( "Before Delete: #directoryExists( "d:\files\documents" )#" );
directoryDelete( "d:\files\documents" );
writeOutput( "After Delete: #directoryExists( "d:\files\documents" )#" );
</cfscript>
Result:-
Before Delete: YES
After Delete: NO
After Rename new: YES
In our system, we delete this d:\files\documents directory and we check if our directory exists before deleting and also check after deleting to confirm whether this directory is deleted or not.

1 Comment
Lorraine
April 27, 2025You’re so awesome! I don’t suppose I have read anything like
this before. So good to discover somebody with some original thoughts on this topic.
Really.. many thanks for starting this up. This
web site is one thing that is required on the
web, someone with a little originality!