After I just posted about how the CFDirectory tag can use the single-character wild card, "?", in its filtering, Steve Withington came in and demonstrated that you can also use the pipe character, "|", to use multiple filters in the same CFDirectory tag. After reading this, I went to the ColdFusion 8 docs but didn't see this listed or mentioned anywhere. As Dan Vega pointed joked, what's the secret handshake you need to get at this kind of information??
Anyway, I ran a quick test, based on my original post, just to see if this worked. In the following demo, I am filtering on files that have the name ben or anna:
<!--- Get all the files that are have either the name ben or anna in them. To separate out the values, we are going to use the pipe "|" character. ---> <cfdirectory action="list" directory="#ExpandPath( './' )#" listinfo="name" filter="anna.*|ben.*" name="qFile" /> <!--- Output file list. ---> <cfdump var="#qFile#" label="File List With Ben Or Anna" />
Running the above code, I get the following CFDump output:
Works quite nicely, like a regular expression. What's odd, though, is that if you look at the CFZip and the CFZipParam tag, they also have a Filter attribute, but they use the comma to separate out different filter values. I wonder why the difference in things that are doing almost the exact same thing.
Want to use code from this post? Check out the license.