List the contents of a directory. Returns either an array, or a query. NOTE: Ensure that you have the required permissions to run this function.
directoryList(path [, recurse] [, listInfo] [, filter] [, sort] [, type])
→ returns any
DirectoryList("//12.3.123.123/c_drive/test");
.
false
true
directoryList traverses the directory tree.
true
false
path
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 following fields: Attributes
, DateLastModified
, Directory
, Link
, Mode
, Name
, Size
, Type
.
name
path
query
*.jpg
. Multiple filters can be applied by using a pipe delimiter. For example: *.doc|*.xls
. You can also pass a function. The arguments of the passed function must have: path
:the file path, type
: The values (file or dir), extension
: The file extension, if any, otherwise and empty string. This argument can also accept the instances of Java FileFilter
Objects. In Lucee 4.5+ it can be a closure as well.
Directory, Size DESC, DateLastModified
. To qualify a column, use asc
(ascending sort a-z) or desc
(descending sort z-a).
all
file
dir
all
filter
param can be a closure as well where the path is passed in. The sort
argument only works when listInfo="query"
.
arrayOfLocalFiles = directoryList( expandPath( "./" ), false, "name" );
queryOfFiles = directoryList( expandPath( "./" ), false, "query", "", "DateLastModified DESC" );
Including sub-directories and as an array containing full paths
arrayOfTempFiles = directoryList( "./", true );
Lucee 4.5+ Pass a closure instead of a string as filter
param
arrayOfFilteredFiles = directoryList(".", false, "name", function(path) {
return ListFindNoCase("Application.cfc,robots.txt,server.json,favicon.ico,.htaccess,README.md", path);
});
Signup for cfbreak
to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.