Notice: With the launch of Adobe Cookbooks, this site will no longer be accepting new entries or posting new content. Thanks to everyone who submitted content!

How do I delete a folder and all files and subfolders beneath it?

The tag has a delete action, but this will throw an error if there is anything in the directory. To remove a directory and everything inside it, simply use the recurse attribute:

<cfset dir = "c:\temp">
<cfdirectory action="delete" directory="#dir#" recurse="true">


This question was written by Raymond Camden.
It was last updated on April 6, 2006 at 5:56:26 PM EDT.

Categories

File and Directory Access

Comments

Comment made by Ryan Guill on April 6, 2006 at 6:15 PM
I think it is importaint to mention that the recurse attribute is a cf 7+ feature. It was possible to do the recursion in earlier versions, but it requires a custom function to be written to do the recursion.


Comment made by Raymond Camden on April 6, 2006 at 6:29 PM
I've said many times now (grin), the cookbook is for "The Latest Release" only. I don't want to have to preface everything with "version X" or "version y". Simply put - the content is for the latest release. (And this is in the FAQ too. ;)