<!--- Tag Parameters --->
<CFPARAM NAME="ATTRIBUTES.Directory">
<CFPARAM NAME="ATTRIBUTES.Filter" TYPE="string" DEFAULT="*.*">
<CFPARAM NAME="ATTRIBUTES.Sort" TYPE="string" DEFAULT="Name">
<CFPARAM NAME="ATTRIBUTES.Name" TYPE="variableName">

<!--- For each filter (filters separated by semicolons) --->
<CFLOOP LIST="#ATTRIBUTES.Filter#" INDEX="ThisFilter" DELIMITERS=";">
  
  <!--- Get query object of matching files --->
  <CFDIRECTORY
    ACTION="LIST"
    DIRECTORY="#ATTRIBUTES.Directory#"
    FILTER="#ThisFilter#"
    NAME="GetFiles">

  <!--- If this is first time through loop, --->
  <!--- Save GetFiles as our "ResultQuery". --->
  <CFIF NOT IsDefined("ResultQuery")>
    <CFSET ResultQuery = GetFiles>
  <!--- If ResultQuery already exists, add --->  
  <!--- GetFiles's records to it via UNION --->
  <CFELSE>
    <CFQUERY DBTYPE="query" NAME="ResultQuery">
      SELECT * FROM ResultQuery
      UNION
      SELECT * FROM GetFiles
      ORDER BY #ATTRIBUTES.Sort#
    </CFQUERY>
  </CFIF>  
  
</CFLOOP>

<!--- Return completed resultset to calling template --->
<CFSET "Caller.#ATTRIBUTES.Name#" = ResultQuery>

