lulu50
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
Thank you for your help
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>
Thank you for your help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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,Get Files.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('.. /UploadedC ontentFile s')#" 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("../Upl oadedConte ntFiles") & 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 ...
what is the cfdirectory query for? i.e. what are you doing with it?
are you sure you want to do "<cfif ListContains(FilesList,Get
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('..
<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("../Upl
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 ...
ASKER
Thank you
ASKER
Open in new window