Deleting all files from a directory or the entire directory tree has become very trivial. Especially since ColdFusion 7 when the recurse attribute was added. With VFS (ram drive) you can use all the same tags to manage drive contents as you would with a physical drive.

So... to remove the entire content of the VFS you can use one line of code:

view plain print about
1<cfdirectory action="delete" directory="ram://" recurse="true" >

However, in doing so ColdFusion throws an error:

The specified directory attribute ram:/// cannot be deleted.
You may not have permissions to delete this directory. The exception occurred during a cfdirectory action="delete".

The essence of the error is true. You can't delete the "ram://" root. So, all you have to do is suppress this error using cftry. But be careful this will not only suppress the error we expect but any unexpected errors as well.

Till next time....