Solved

CFFILE delete - file name has pound sign, cannot delete it

Posted on 2004-09-08
9
238 Views
Last Modified: 2013-12-24
I am trying to delete a file that had been previously uploaded.  Code works fine until the user uploaded a file with a '#' in the file name i.e. test#2.txt.  Am getting an error message:

Unable to delete the file '\\xxxxxx\test.' The system cannot find the file specified. (error 2)

<cfparam name="file_name_delete" default="">

<cffile action="DELETE" file= "#Replace(dest_path,"##","####","All")#\#Replace(file_name_delete,"##","####","All")#">

The parameter is being passed in from the same template as follows:

<a href="xxxxx.cfm?app_id=#app_id#&attachment_id_delete=#qry_attachment.attachment_id#&file_name_delete=#Replace(qry_attachment.file_name,"##","####","All")#" class="StdTextLink">Delete</a>

Seems that I am not able to use the replace command withing the cffile tag - any suggestions as to how to work around this?

thanks very much!
0
Comment
Question by:jennilee13
9 Comments
 
LVL 17

Expert Comment

by:Tacobell777
Comment Utility
Have you tried just hardcoding the full path to see if you have the right path?
<cffile action="DELETE" file="c:\path\test##2.txt">


Or do a <cfset myPath = Replace(dest_path,"##","####","All") & "\" &Replace(file_name_delete,"##","####","All")>

then output myPath and see if the generated path is correct.
0
 

Author Comment

by:jennilee13
Comment Utility
The path is correct as the code works perfectly on files without a "#".  I put in a hard-coded file name with two '#'s in it and the file was deleted correctly.  I tried doing the replace function outside of the cffile delete, as you describe above, still same error message.  I cannot get the 'file' variable in the cffile tag to recognize that there are two ##.  It seems like it is only seeing the first #, no matter what i do!
0
 

Author Comment

by:jennilee13
Comment Utility
opps, you were correct - it looks like the problem is in passing the file name in upon the submit in the href as the portion of the file name including and after the # is truncated.   So it now seems as if the replace function in the href is not properly adding the additional #?
0
 
LVL 17

Expert Comment

by:Tacobell777
Comment Utility
hold on, you are getting the file name value from a database right? The when you output it, it should not have to be escaped again, as its a string and not evaluated again..
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 10

Expert Comment

by:Mause
Comment Utility

Tacobell is right the value of your variable won't be evaluated

so <cffile action="DELETE" file= "#dest_path#\#file_name_delete#"> will be enough

0
 

Author Comment

by:jennilee13
Comment Utility
Then why is the file name value being truncated after the # sign after the submit?  I am getting the name from a database, it is then displayed on the screen.  The user can then click on the delete button and the value from the db is passed via the href to the same template where there is some logic at the top that decides if the delete action should take place.   I display the value passed right before the cffile funtion and it has been truncated, i am assuming during the processing that takes place when the delete key is clicked and the template is re-loaded?

The code did not contain the replace function previously (i put that in to try to resolve the problem) and had been working for years!  Again, until the dang user decides they want file names with # signs!

uggg!
0
 

Author Comment

by:jennilee13
Comment Utility
by going through some other web searches finally came up with the solution myself - needed to have the href formatted as
follows:


<a href="xxxxx.cfm?app_id=#app_id#&attachment_id_delete=#qry_attachment.attachment_id#&file_name_delete=#URLEncodedFormat(qry_attachment.file_name)#" class="StdTextLink">Delete</a>

then the cffile tag would be:

<cfparam name="file_name_delete" default="">

<cffile action="DELETE" file= "#dest_path#\#file_name_delete#">

no replace function was required at all.  Can i award myself the points?? :~)

0
 

Accepted Solution

by:
CetusMOD earned 0 total points
Comment Utility
PAQed, with points refunded (300)

CetusMOD
Community Support Moderator
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now