Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible somehow to exclude files with cfdirectory?

When using cfdirectory, how could I exclude all cfm files and list all others without specifying the file extensions for all files I want to see, or exclude a specific file like index.html without doing a query of query?

I'm looking for something like the following, notice the filter attribute.

<cfdirectory directory="#ExpandPath('./')#" action="list" name="qryFiles" filter="!index.html" sort="name ASC" listinfo="name">

or:

<cfdirectory directory="#ExpandPath('./')#" action="list" name="qryFiles" filter="!*.cfm" sort="name ASC" listinfo="name">
like image 682
Jayson Avatar asked Jul 06 '09 20:07

Jayson


4 Answers

The filter attribute is useless if you're trying to do a an exclusion. Case in point: Just yesterday I wanted to use cfdirectory to grab all the subdirectories but EXLCUDE any directory that started with a period "." so that I could exclude things like ".svn" and ".git". Needless to say I searched all over the place and couldn't find an answer.

In the end I ended up just using some conditional logic in my loop:

<cfloop query="mydir">
  <cfif left(name, 1) neq ".">
    <!--- do some code --->
  </cfif>
</cfloop>

Which got the job done. Of course I could of used a QoQ, but to me adding all that overhead to filter out directories that began with a period seemed silly.

Bottom line is that, yes, we're screwed when it comes to exclusion filtering with cfdirectory, but there's no reason you can't use your imagination and a little bit of code to get the results that you want.

like image 187
rip747 Avatar answered Sep 25 '22 22:09

rip747


No, it's not possible to exclude files with cfdirectory alone. The filter attribute only specifies which files to include, with DOS style wildcards (* and ?).

The simplest solution is probably to filter after the fact with cfquery.

<cfquery name="qryFiles" dbtype="query">
    SELECT * FROM qryFiles
    WHERE name not like '%.cfm'
</cfquery>
like image 36
Patrick McElhaney Avatar answered Sep 25 '22 22:09

Patrick McElhaney


You could create a custom tag that ran the CF directory then looped over the results (like you have) building up a new query or a structure with your results in. That would make is slightly more re-usable in other situations.

like image 20
Ian Avatar answered Sep 24 '22 22:09

Ian


It may be possible to do this in a java object with..

CreateObject("java", "java.io.File");  

..and a filename filter

Personally, I think you would be better off just using a query of queries.

like image 26
Nick Van Brunt Avatar answered Sep 25 '22 22:09

Nick Van Brunt