Skip to main content
Inspiring
May 7, 2008
Question

deleting directory

  • May 7, 2008
  • 1 reply
  • 273 views
I am trying to delete the records and the directories related to it but in some cause i am facin a problem.

Here is my Code

<cfif isdefined('form.realdel')>
<cfset session.holdRecord = ListToArray(#Form.thisCampSchool#)>
<cfinvoke
component="EcoLife.admin.CFC.users"
method="thisDelete">
<cfinvokeargument name="willgetDeleted" value="#trim(form.thisCampSchool)#"/>
</cfinvoke>
<cfloop index="x" array="#session.holdRecord#">
<cfoutput>
<cfdirectory action="delete" recurse="yes" directory="#websitename#attachments/schools/#x#">
</cfoutput>
</cfloop>
<cflocation addtoken="no" url="campadd.cfm?msg=3">
</cfif>

The holdRecord will hold the value of the select boxes selected like 3,4,5,6,7,8,9,10 and then i am moving them to the array so i can loop over array and delete the directory related to it.

But when i try to delete it..

It deletes the records based on the cfinvoke tag from the database. and then it comes to cfdirectory and say that the folder does not exists, while the folder do exist over there.

The paths i am using are correct and i have checked 10 times before posting here..

i ma storing the values in the session so they should not be removed but no luck, can anyone tell me how this can be resolved

Chers and regards

Thanks
    This topic has been closed for replies.

    1 reply

    Inspiring
    May 7, 2008
    1) you do not have to convert your list to array to loop over it - you
    can loop over a list just the same as over array.

    2) no need for those <cfoutput> tags inside your cfloop

    3) the DIRECTORY attribute of <cfdirectory> tag requires a FULL ABSOLUTE
    PATH to the directory.
    does #websitename#attachments/schools/ resolve to an absoute path like
    'C:\Inetpub\wwwroot\yoursite\attachments\schools\'? or does it resolv to
    something like 'mywebsite/attachments/schools/'?
    you can use expandpath() function to convert a realative path to an
    absolute path if you need to.

    4) though i think the 3) above is the cause of your problem, and even
    though you said you checked your paths 10 times, still just to check:
    sure you are not missing a / after #websitename#?

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/
    Inspiring
    May 7, 2008
    Sometimes if the folder you are trying to delete has files in it, you may have to delete them before you can delete the folder itself. Do an inner loop of CFFILE to remove any files in the folder.