Solved

Delete multiple files with CFFILE

Posted on 2006-07-12
9
323 Views
Last Modified: 2013-12-24
I have a page which shows a list of images in a table,
output from a cfdirectory function.

I currently have it working with radio buttons - select one image,
click delete button, and form processes back to same page, performing and confirming the deletion.

I want to change this to use checkboxes, and allow multiple deletions.
Currently, each radio button is a field called 'delete' with the name of the image
as the value. The name is passed to the delete function as #form.delete# ... works great!

However, when I change it to checkboxes, the value of #form.delete# comes through as multiple file names separated by a comma.

How can I take the value "c:/domains/path/images/filename.jpg, filename2.,jpg, filename3.jpg" and separate out all the filenames - basically trim off everything including the last /, then separate the remaining string by commas, removing spaces.

THEN I need to somehow loop the delete function, running through each of the filenames.

any suggestions?
0
Comment
Question by:MichaelEvangelista
  • 5
  • 3
9 Comments
 
LVL 18

Expert Comment

by:Plucka
ID: 17097311
MichaelEvangelista,

Easy!

<cfloop index="file" list="#form.delete#">
    <cffile action="delete" file="#listLast(file, "/")#" />
</cfloop>

So you are looping over the list of names, then getting for each name the last element in the list where the delimiter is a "/"

Make sense?

Regards
Plucka
0
 

Author Comment

by:MichaelEvangelista
ID: 17097369
Yes and no....

If you look at my example, the path comes through as one big long path string with a comma separated list after the last /

so it is like

"C:/domains/thissite.com/wwwroot/images/img1.jpg, img2.jog, img3.jpg"

SO... I think I need to first cut off everything up to that last /, then separate by comma from what is left. Does that make sense?
0
 
LVL 18

Expert Comment

by:Plucka
ID: 17097393
No,

My example will work just fine.

Try it

Regards
Plucka
0
 

Author Comment

by:MichaelEvangelista
ID: 17097476
thanks, Plucka - but I must not be doing it right.
I actually have 3 delete functions, as this is a photo gallery type setup,
I am deleting from 3 seprate folders.

I changed this

 <cfoutput>
   <cffile action="Delete" file="#imagesPath#original/#form.delete#">
   <cffile action="Delete" file="#imagesPath#full/#form.delete#">
   <cffile action="Delete" file="#imagesPath#thumb/#form.delete#">
  </cfoutput>

to this

<cfloop index="file" list="#form.delete#">
  <cfoutput>
   <cffile action="Delete" file="#imagesPath#original/ #listLast(form.delete, "/")#">
   <cffile action="Delete" file="#imagesPath#full/#listLast(form.delete, "/")#">
   <cffile action="Delete" file="#imagesPath#thumb/#listLast(form.delete, "/")#">
  </cfoutput>
</cfloop>

**But I still get this error:

The destination "c:/domains/mredesign.com/wwwroot/MREcfCMS/images/original/ sampleJPG5.jpg,stress1.jpg" specified in the CFFILE tag is invalid.

See what I mean...?

That full path is coming from the variable #imagespath#...  but the filenames are still comma separated.
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 15

Expert Comment

by:tim_cs
ID: 17097892
Just a slight variation on what Plucka had that might work for you.


<cfloop index="file" list="#listLast(form.delete, "/")#">
  <cfoutput>
   <cffile action="Delete" file="#imagesPath#original/#file#">
   <cffile action="Delete" file="#imagesPath#full/#file#">
   <cffile action="Delete" file="#imagesPath#thumb/#file#">
  </cfoutput>
</cfloop>
0
 
LVL 18

Accepted Solution

by:
Plucka earned 250 total points
ID: 17098026
Sorry

Use the wrong variable in the listLast. This works.

<cfset form.delete = "C:/domains/thissite.com/wwwroot/images/img1.jpg, img2.jog, img3.jpg" />
<cfset imagesPath = "C:/domains/mredesign.com/wwwroot/MREcfCMS/images/" />

<cfloop index="fileName" list="#form.delete#" delimiters=",">
    <cfoutput>#imagesPath##trim(listLast(fileName, "/"))#<br /></cfoutput>
</cfloop>

NOTE: I added the trip as your list seems to have spaces.

This displays them so you can change the cfoutput for

<cfloop index="fileName" list="#form.delete#" delimiters=",">
   <cffile action="Delete" file="#imagesPath#original/ #listLast(fileName, "/")#">
   <cffile action="Delete" file="#imagesPath#full/#listLast(fileName, "/")#">
   <cffile action="Delete" file="#imagesPath#thumb/#listLast(fileName, "/")#">
</cfloop>

NOTE: You don't need the <CFOUTPUT around the <CFFILE
0
 

Author Comment

by:MichaelEvangelista
ID: 17111157
perfect, thank you!
( except.. there is a space in your code after original/ in the first cffile, no prob to fix.)

NOW... how can I tell how many files were deleted?
I need to show the number of files on the confirmation.

Also, how can I tell how many checkboxes are checked on the initial page, with js or cf? I would like to show a message - Delete *4* files?

Here is the page now...
http://tinyurl.com/omlyl

thanks!


 
0
 

Author Comment

by:MichaelEvangelista
ID: 17111559
OOPS you have to be logged in to see delete.
Click log out, then enter superadmin / superadmin,
then go to 'image list'


http://tinyurl.com/omlyl


sorry
0
 

Author Comment

by:MichaelEvangelista
ID: 17111633
GOT the loop count working, so... good to go... thanks!!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

910 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

22 Experts available now in Live!

Get 1:1 Help Now