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

directoryList(path [, recurse] [, listInfo] [, filter] [, sort] [, type]) → returns any

directoryList Argument Reference

path string

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

recurse boolean
Default: false

If true directoryList traverses the directory tree.
  • true
  • false

listInfo string
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.
  • name
  • path
  • query

filter string

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

sort string

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

type string
Default: all

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



Version 9+ Only CF11+ 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