Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CFFILE DELETE through a directory

Status
Not open for further replies.

Yelellav

Programmer
Feb 7, 2002
12
US
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=&quot;list&quot;
directory=&quot;#form.docDelete#&quot;
name=&quot;file_list&quot;>


<!---loop through list and delete all files in the list--->

<cfloop query=&quot;file_list&quot;>

<!--- delete all files within the folder --->
<cfif fileexists(form.docDelete & &quot;\&quot; & file_list.name)>
<cffile action=&quot;delete&quot;
file=&quot;#form.docDelete#\#file_list.name#&quot;>
</cfif>
</cfloop>


<!--- delete the folder --->

<cfdirectory action=&quot;delete&quot; directory=&quot;#form.docDelete#&quot;>

 
the path for the cffile delete is wrong. u must put the path of the server (i.e. c:\inetpub\ ). That's why it doesn't delete the files and so it can't delete the folder. And u must put the path server in the cfdirectory delete too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top