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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with deleting directories that are not empty

Status
Not open for further replies.

mike2277

Programmer
Mar 25, 2002
54
US

Hi, I am in the process of moving my ColdFusion application over from a server using ColdFusion 5.0 to a different server using ColdFusion MX. So far, I have found the transition to be pretty painless. However, I did come across one glitch that I just can’t seem to figure out.

I have been using a custom tag called CF_DeleteDirectory to delete directories that may contain one or more files or subdirectories. On the ColdFusion 5.0 server I have never had a problem with my code but moving it to the MX server has created the following error message every time:

The specified Directory attribute F:\AcademyPAWebSite\eschool\courses\1836\1716 cannot be deleted.
This directory is not empty. This condition was encountered during a cfdirectory action="DELETE".

The error occurred in F:\AcademyPAWebsite\eschool\securePages\BUILDER\DeleteDirectory.cfm: line 53
51 :
52 : <!--- DELETE THE DIRECTORY --->
53 : <CFDIRECTORY ACTION=&quot;DELETE&quot; DIRECTORY=&quot;#attributes.directory#&quot;>
54 : <CFSETTING ENABLECFOUTPUTONLY=&quot;No&quot;>
55 :


In this example, the directory I am trying to delete is labeled “1716” and it contains numerous files and subdirectories inside it.

I code I am using on my “deleteLesson.cfm” template is:

<CFMODULE
Template=&quot;DeleteDirectory.cfm&quot;
directory=&quot;F:\AcademyPAWebSite\eschool\courses\#URL.CourseID#\#url.LessonID#&quot;>


The actual code of the custom tag (DeleteDirectory.cfm) is:

<!--- MAKE SURE THE DIRECTORY EXISTS --->
<CFIF NOT DirectoryExists(attributes.directory)>
<CFTHROW MESSAGE=&quot;The Directory (#attributes.directory#) Does Not Exist!&quot;>
</CFIF>
<!--- Kill any leading &quot;\&quot; in the directory --->
<CFIF right(attributes.directory,1) is &quot;\&quot;>
<CFSET attributes.directory = left(attributes.directory,len(attributes.directory)- 1)>
</CFIF>

<!--- CHECK THE CONTENTS OF THE DIRECTORY --->
<CFDIRECTORY ACTION=&quot;LIST&quot; DIRECTORY=&quot;#attributes.directory#&quot; NAME=&quot;TheDir&quot;>

<!--- IF THE DIRECTORY IS NOT EMPTY, GO THROUGH AND EMPTY IT --->
<CFIF TheDir.Recordcount GT 2>
<CFLOOP QUERY=&quot;TheDir&quot;>
<CFIF Type is &quot;File&quot;>
<CFFILE ACTION=&quot;DELETE&quot; FILE=&quot;#attributes.directory#\#Name#&quot;>
<CFELSEIF Type is &quot;Dir&quot; and name is not &quot;.&quot; and name is not &quot;..&quot;>
<CF_DeleteDirectory DIRECTORY=&quot;#attributes.directory#\#Name#&quot;>
</CFIF>
</CFLOOP>
</CFIF>

<!--- DELETE THE DIRECTORY --->
<CFDIRECTORY ACTION=&quot;DELETE&quot; DIRECTORY=&quot;#attributes.directory#&quot;>
<CFSETTING ENABLECFOUTPUTONLY=&quot;No&quot;>

<!---Copyright, 1999 Control Data Systems, Inc.
--->

I tested to make sure the url variables were indeed being passed correctly and they are, so I don’t think that is the problem.

If anyone can assist me with this problem I would really appreciate it!

Thanks,

Mike


 
mike,

the only thing that i can think of is that MX now does not return the . and the .. directories that it used to in previous version of CF. which i am assuming is what you are looking for with this statement:

<CFIF TheDir.Recordcount GT 2>

under CF 5 a CFdirectory would return the following:

.
..
1716
file.cfm

under MX it will return:

1716
file.cfm

so you check will stop the code from deleting the contents fo the directory. So what CF is telling you is true there are still files/directories in the directory you want to delete.

change you if statement to read:

<CFIF TheDir.Recordcount GT 0>

and i think that should sort out your problem.

Hope this helps!

Tony
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top