cfdirectory filter files and folders in ColdFusion

1.3k Views Asked by At

I'm trying to extract the directory structure and want to include all the sub dirs, but apply a filter on the files that are returned, using CFDIRECTORY.

If I use

<cfdirectory directory="#initialDir#" 
             recurse="yes" 
             name="files" 
             sort="type asc"
             type="all" >

Then it will give me all the files and sub folders.

if I then add in a filter

<cfdirectory directory="#initialDir#" 
             recurse="yes" 
             name="files" 
             sort="type asc"
             type="all" 
             filter="index.cfm|page_*.cfm" >

It gives me just the index and page_* files, but NOT the directories. Is there a way of adding something into the filter to also pull in the directories, regardless of their name (exclude the Dir from the filter?).

I know that I could simply run with the first option and then do a QoQ against the results, but I want to minimize the amount of data I'm working with, and as there could be potentially thousands of files in a directory structure, I'd rather not have to wait for cfdirectory to pull them all through and then trim down the results. Working with a much smaller dataset from the start would be much more efficient and a lot faster!

Anybody have an idea?

0

There are 0 best solutions below