Deleting multiple files with CFFILE

Posted on 2004-11-02
Last Modified: 2013-12-24
I want to delete all files on a directory as a scehduled cleanup function.

I gather CFFILE doesn't allow filename templates like so:

    <cffile action = "delete" file = "\test\badfile*.png">

Does anyone have a handy loop for doing this?

Question by:451ls
    LVL 7

    Expert Comment

    Use <cfdirectory> to get file names.  Loop over results and delete files with <CFFILE>


    <cfexecute> to delete files like "c:\test\del *.png"
    LVL 22

    Expert Comment

    INSDivision6 good answer.
    Though I usually use CFdirectory as it is not related with any platform.
    Though, nothing wrong with either of them.
    LVL 17

    Accepted Solution

    <cfset = "c:\temp\" />

          name="qDirectory" />

    <cfloop query="qDirectory">
                      file="" />
                      <p>Could not delete file:</p>

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Article by: kevp75
    Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
    Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    737 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

    16 Experts available now in Live!

    Get 1:1 Help Now