?
Solved

batch delete files in directory Coldfusion

Posted on 2010-01-07
4
Medium Priority
?
273 Views
Last Modified: 2012-05-08
I have a list of files in a database. I would like read this list and dynamically delete the files in a directory based on this list. Using ColdFusion. Possible?
0
Comment
Question by:ecpeel
  • 2
  • 2
4 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 2000 total points
ID: 26203221
Approx how many files?  If it is a small to moderate number of files:

1. Query the database to get the file names
<cfquery name="getFiles" ...>
       SELECT  FileName FROM YourTable
</cfquery>

2. Loop through the query, and construct the absolute path to each file ie c:\someDir\myFile1.doc, ...).  Then use
FileDelete() or CFFILE to delete each one.   I'll assume you're only storing the file name in the db. So adjust the code as needed.

<cfset baseDir = "c:\someDirec">
<cfloop query="getFiles">
          <cfset fullPathToFile = baseDir &"\"& FileName >
          <cfset FileDelete(fullPathToFile) />          
</cfloop>

http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_e-g_08.html
 
0
 

Author Comment

by:ecpeel
ID: 26203307
checking it out agx. thanks for the quick response.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 26203346
You're welcome.  Ignore the code just beyond the link. That a copy + paste error.

0
 

Author Closing Comment

by:ecpeel
ID: 31674160
Thank you so much
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
The viewer will learn how to dynamically set the form action using jQuery.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

809 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