Link to home
Start Free TrialLog in
Avatar of lulu50
lulu50Flag for United States of America

asked on

<cffile cannot delete a file

Hi,

I don't know what I'm doing wrong.

I need to compare the folder file name with the name in the database and delete them.

this is my code that does not work

<cfquery name="GetFiles" datasource="#strDSN#" username="#strUID#" password="#strPWD#">  
	Select Path from TestingContentUploadFile
    where ContentID = #URL.ContentID#
</cfquery>

<cfif IsDefined('GetFiles') and #GetFiles.RecordCount# gt 0>

<cfset FilesList = valueList(GetFiles.Path)/>

<cfdirectory 
   directory="expandpath('../UploadedContentFiles')" name="ContentFiles">

<CFLOOP QUERY="GetFiles"> 
       <cfif ListContains(FilesList,GetFiles.Path)>
      <cffile action="delete" file="#ExpandPath( '../UploadedContentFiles/#GetFiles.Path#')#"> 
       </cfif>
</CFLOOP>

Open in new window



Thank  you for your help
Avatar of lulu50
lulu50
Flag of United States of America image

ASKER

I tried this but still not working


  <cffile action="delete" file="#ExpandPath( '..\UploadedContentFiles\' )##GetFiles.Path#"> 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
a couple questions
what is the cfdirectory query for? i.e. what are you doing with it?

are you sure you want to do "<cfif ListContains(FilesList,GetFiles.Path)>" when fileslist IS the valuelist of the getFiles query column path???

and I see you are doing listcontains instead of listcontainsnocase - CF sometimes converts to uppercase so who knows if that's it this time. OR maybe it is a different case on disk than in the db. ??

can you post an image of a cfdump for both the getFile query and the directory "uploadedcontentfiles"?

<cfquery name="GetFiles" datasource="#strDSN#" username="#strUID#" password="#strPWD#">  
      Select Path from TestingContentUploadFile
    where ContentID = #URL.ContentID#
</cfquery>
<cfdump var="#GetFiles#">

<cfdirectory directory="#expandpath('../UploadedContentFiles')#" name="ContentFiles">
<cfdump var="#ContentFiles#">
verify of course that this path is correct for uploadedcontentfiles

You can also try a variant of expandPath() which would be
<cffile action="delete" file="#(ExpandPath("../UploadedContentFiles") & GetFiles.Path)#">
I stumbled onto a situation where the server was choking on the one version - anyway you can try it if you want - probably not it ...

good luck ...
Avatar of lulu50

ASKER

Thank you