Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2004-09-08
9
242 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
ID: 12011380
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
ID: 12011648
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
ID: 12011715
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
Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

 
LVL 17

Expert Comment

by:Tacobell777
ID: 12012673
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
 
LVL 10

Expert Comment

by:Mause
ID: 12015010

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
ID: 12017728
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
ID: 12018832
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
ID: 12289311
PAQed, with points refunded (300)

CetusMOD
Community Support Moderator
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

790 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