batch delete files in directory Coldfusion

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?
ecpeelAsked:
Who is Participating?
 
_agx_Commented:
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
 
ecpeelAuthor Commented:
checking it out agx. thanks for the quick response.
0
 
_agx_Commented:
You're welcome.  Ignore the code just beyond the link. That a copy + paste error.

0
 
ecpeelAuthor Commented:
Thank you so much
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.