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?
Who is Participating?
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

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

ecpeelAuthor Commented:
Thank you so much
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.