directoryList

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

path
Required

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

recurse
Default: false

If true directoryList traverses the directory tree.

listInfo
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

filter

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

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

type
Default: all

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

Compatibility

ColdFusion:

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

Lucee:

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