Skip to main content
Inspiring
July 16, 2013
Answered

Deleting Files

  • July 16, 2013
  • 2 replies
  • 935 views

I have a database table that stores a destroy date for uploaded files.

The files are stored in one directory.

I'm a little lost on how to delete the file / files from the directory when the destroy date is due.  I will mark them in the database as destroyed.

All of the files live in the same directroy and they are all pdf files.

The scan_doc table lists the folder they file is stored in and the name of the file is the primary key from the table, so a file I might want to delete looks like this:

H:\scanned_files\10\175.pdf

It seems like i should be releatively easy, but for a simple person like me, I'm stumped.

I was thinking of a query to select files that are listed as detroyed, that part I can figure out, then I need the logic to delete the file(s).

Any help would be appreciated.

Thanks

    This topic has been closed for replies.
    Correct answer p_sim

    Please ignore my previous reply. It should be like this:

    <cfquery datasource="myDSN" name="get_due_file">

              SELECT folder, filename

              FROM scan_doc

              WHERE destroyed = 1;

    </cfquery>

    <!---

              Assuming the output of the query looks like below:

                        folder = H:\scanned_files\10\

                        filename = 175.pdf

    --->

    <cfloop query="get_due_file">

              <cffile action="delete" file="#folder##filename#" />

    </cfloop>

    2 replies

    p_sim
    p_simCorrect answer
    Participating Frequently
    July 17, 2013

    Please ignore my previous reply. It should be like this:

    <cfquery datasource="myDSN" name="get_due_file">

              SELECT folder, filename

              FROM scan_doc

              WHERE destroyed = 1;

    </cfquery>

    <!---

              Assuming the output of the query looks like below:

                        folder = H:\scanned_files\10\

                        filename = 175.pdf

    --->

    <cfloop query="get_due_file">

              <cffile action="delete" file="#folder##filename#" />

    </cfloop>

    ctreevesAuthor
    Inspiring
    August 5, 2013

    Perfect, thank you.

    p_sim
    Participating Frequently
    July 16, 2013

    <cfloop query="yourSelectedFiles">

      <cfdirectory action="delete" .........>

    </cfloop>

    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7f99.html