Description:-

This is used to get a list of the contents of the on-disk or in-memory directory. Also lists the contents of the sub-directories if the recurse is set to true.

directoryList( path, recurse, listInfo, filter, sort, type );

Attributes:-

path:- This is a required attribute, and the name of the directory from which to list the contents, It can be an absolute on-disk or in-memory location. Alternatively, you can specify the IP address as in the bellow example:
directoryRename( "//192.168.0.1/new_disc/test", "" );

recurse:- This is a non-required attribute, and If it set true directoryList traverses the directory tree. The default value is false.

listInfo:- This is a non-required attribute and 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 following fields: AttributesDateLastModifiedDirectoryLinkModeNameSizeType. The default value is path.

filter:- This is a non-required attribute, File extension filter applied to the listed files, for example, *.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 an empty string. This argument can also accept the instances of Java FileFilter Objects.

sort:- This is a non-required attribute, Columns by which to sort. e.g. Directory, Size DESC, DateLastModified. To qualify a column, use asc (ascending sort a-z) or desc (descending sort z-a).

type:- This is a non-required attribute, Filter the result to only include files, directories, or both. values are:- file, dir, all. Only ColdFusion 11+ supports the type argument.

Example:-

In this example, we will get an array that contains this d:\files\documents directory’s contents only.

<cfscript>
    writeOutput( directoryList( "d:\files\documents", false, "name" ) );
</cfscript>

Result:-

array
1	new.jpg
2	icon.gif
3	test.txt

In our d:\files\documents directory we already have some files, which you can see in the result.