batch delete files in directory Coldfusion

Posted on 2010-01-07
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?
Question by:ecpeel
    LVL 51

    Accepted Solution

    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) />          

    Author Comment

    checking it out agx. thanks for the quick response.
    LVL 51

    Expert Comment

    You're welcome.  Ignore the code just beyond the link. That a copy + paste error.


    Author Closing Comment

    Thank you so much

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math ( While this method is not o…
    Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them ( . I did keep the main js functions but made sever…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    733 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

    19 Experts available now in Live!

    Get 1:1 Help Now