Can anyone help me figure out how to recurse through the directory to delete multiple levels of files and folders using CFFILE.
I can delete the top level fine (i.e. one folder and all files in that folder), but when I try to delete a folder within a folder that contains files I get the error that I can not delete the folder because files exist. I understand why I am getting the error but I don't know how to resolve this.
Any help would be greatly appreciated.
My code below works fine for the "first level"
<!--- put files within directory into a list --->
<cfdirectory action="list"
directory="#form.docDelete#"
name="file_list">
<!---loop through list and delete all files in the list--->
<cfloop query="file_list">
<!--- delete all files within the folder --->
<cfif fileexists(form.docDelete & "\" & file_list.name)>
<cffile action="delete"
file="#form.docDelete#\#file_list.name#">
</cfif>
</cfloop>
<!--- delete the folder --->
<cfdirectory action="delete" directory="#form.docDelete#">
I can delete the top level fine (i.e. one folder and all files in that folder), but when I try to delete a folder within a folder that contains files I get the error that I can not delete the folder because files exist. I understand why I am getting the error but I don't know how to resolve this.
Any help would be greatly appreciated.
My code below works fine for the "first level"
<!--- put files within directory into a list --->
<cfdirectory action="list"
directory="#form.docDelete#"
name="file_list">
<!---loop through list and delete all files in the list--->
<cfloop query="file_list">
<!--- delete all files within the folder --->
<cfif fileexists(form.docDelete & "\" & file_list.name)>
<cffile action="delete"
file="#form.docDelete#\#file_list.name#">
</cfif>
</cfloop>
<!--- delete the folder --->
<cfdirectory action="delete" directory="#form.docDelete#">