Minor tip here, but over the weekend, at cf.Objective(), I was watching a presentation (I think it was Mark Mandel) when I saw that someone was using a ColdFusion CFDirectory filter that had the "?" wild card. I knew that CFDirectory filtering could use the multi-character "*" wild card, but I am pretty sure I didn't know that it could use the single-character wild card. Very cool!. How did this escape my attention? I ran a quick test just to make sure I wasn't misunderstanding what was going on. In this demo, I am going to list all files in a directory followed by a list of only the files that have a three character file name:
<!--- Get all files. ---> <cfdirectory action="list" directory="#ExpandPath( './' )#" listinfo="name" name="qFile" /> <!--- Output file list. ---> <cfdump var="#qFile#" label="All Files" /> <br /> <!--- Get files that have only THREE characters followed by and extension type. ---> <cfdirectory action="list" directory="#ExpandPath( './' )#" listinfo="name" filter="???.*" name="qFile" /> <!--- Output file list. ---> <cfdump var="#qFile#" label="File List With Three Characters" />
This gives us the following two CFDump outputs:
Works like a charm. This would definitely have come in handy several times in the past. At least I will know it going forward. I just looked in the ColdFusion 8 documentation to see if this was mentioned and sure enough, it's right there. I guess I have to be better about reading the documentation.
Want to use code from this post? Check out the license.