List the contents of a directory. Returns either an array, or a query.

directoryList(path [, recurse] [, listInfo] [, filter] [, sort] [, type]) → returns query|array

directoryList Argument Reference


The path to a directory. If given a relative path, that path will be relative to the server"s temp directory.

Default: false

If true directoryList traverses the directory tree.

Default: path

Sets the return type. name returns an array with only the file names, path returns an array with the full path names and query returns a query containing the follwing fields: Attributes, DateLastModified, Directory, Link, Mode, Name, Size, Type. Values:
  • name
  • path
  • query


Applies a filter to the listed files, for example, *.jpg. Multiple filters can be applied by using a pipe delimiter. For example: *.doc|*.xls


Columns by which to sort. e.g. Directory, Size DESC, DateLastModified.

Default: all

CF 11+ Filter the result to only include files, directories, or both. Values:
  • file
  • dir
  • all



Version 9+ Only CF 11+ supports the type argument.


The sort argument only works when listInfo="query".

Examples sample code invoking the directoryList function

An array of files in this directory

arrayOfLocalFiles = directoryList( expandPath( "./" ), false, "name" );

A query of files in this directory sorted by date last modified

queryOfFiles = directoryList( expandPath( "./" ), false, "query", "", "DateLastModified DESC" );

An array of files in the temp directory

Including sub-directories and as an array containing full paths

arrayOfTempFiles = directoryList( "./", true );

Fork me on GitHub