Delete multiple files with CFFILE

Posted on 2006-07-12
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?
Question by:MichaelEvangelista
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
  • 5
  • 3
LVL 18

Expert Comment

ID: 17097311


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

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?


Author Comment

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/, 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?
LVL 18

Expert Comment

ID: 17097393

My example will work just fine.

Try it

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.


Author Comment

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

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

to this

<cfloop index="file" list="#form.delete#">
   <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, "/")#">

**But I still get this error:

The destination "c:/domains/ 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.
LVL 15

Expert Comment

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

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

Accepted Solution

Plucka earned 250 total points
ID: 17098026

Use the wrong variable in the listLast. This works.

<cfset form.delete = "C:/domains/, img2.jog, img3.jpg" />
<cfset imagesPath = "C:/domains/" />

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

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, "/")#">

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

Author Comment

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...



Author Comment

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


Author Comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Troubleshoot mediawiki <-> ActiveDirectory authentication 2 140
Reverse Proxy Server 6 96
IIS Site Configuration Copy 2 82
site launch date and last modified date 3 105
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
What You Need to Know when Searching for a Webhost Provider
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 …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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