Search code examples
coldfusioncfdirectory

ColdFusion DirectoryList () - is it possible to get only directories?


I've used <cfdirectory> to get only directories, but I need to do this inside a UDF written in cfscript, so I need to use DirectoryList(). It appears that I need to get everything and then visit the result filtering directories manually. However, there is a filter parameter... can it be used to filter only directories? If so, what would be the filter?

I haven't found an example that will return only directories, and the documentation is not clear on what can be filtered (except for *.txt).


Solution

  • Unfortunately, no. Unlike cfdirectory's type attribute, filters are only applied to the file/directory names. So I do not think it is possible to use filter to find directories only. Keep in mind you can always wrap cfdirectory in a function, then call it from your UDF. That is what the old DirectoryList function at cflib.org does.

    the documentation is not clear on what can be filtered (except for *.txt).

    You can only search the name. filter supports partial patterns (like find files containing "xxx"), searching by file extensions, or you could apply multiple patterns by using "|":

    *test*        // partial pattern. names containing the word "test"
    *.xls         // find Excel files
    *test*|*.xls  // find names containing "test" OR Excel files
    

    However, since the pattern is only applied to the name, it cannot be used to reliably identify directories.