Manages interactions with directories.
<cfdirectory
action = "directory action"
directory = "directory name"
name = "query name"
filter = "list filter"
mode = "permission"
sort = "sort specification"
newDirectory = "new directory name">
ColdFusion MX:
action = "list":
cfdirectory
action = "list"
no longer returns the directory entries "."
(dot) or ".."
(dot dot), which represent "the current directory" and "the parent directory."cfdirectory
action = "list"
no longer returns the values of the Archive and System attributes.cfdirectory
action = "list"
does not return any information in the mode
column.Attribute | Req/Opt | Default | Description |
---|---|---|---|
action |
Optional |
List |
|
directory |
Required |
|
Absolute pathname of directory against which to perform action. |
name |
Required if |
|
Name for output record set. |
filter |
Optional if |
|
File extension filter applied to returned names. For example: *.cfm. One filter can be applied. |
mode |
Optional |
|
Used with
|
sort |
Optional; used if |
ASC |
Query column(s) by which to sort directory listing. Delimited list of columns from query output. To qualify a column, use:
For example: sort = "dirname ASC, file2 DESC, size, datelastmodified" |
newDirectory |
Required if |
|
New name for directory |
Note: For this tag execute, it must be enabled in the ColdFusion Administrator. For more information, see Configuring and Administering ColdFusion MX.
If you put ColdFusion applications on a server that is used by multiple customers, you must consider the security of files and directories that could be uploaded or otherwise manipulated with this tag by unauthorized users. For more information about securing ColdFusion tags, see Configuring and Administering ColdFusion MX.
If action = "list"
, cfdirectory
returns these result columns, which you can reference in a cfoutput
tag:
name
: directory entry name. The entries "."
and ".."
are not returned. size
: directory entry sizetype
: file type: File, for a file; Dir, for a directorydateLastModified
: the date that an entry was last modifiedattributes
: file attributes, if applicablemode
: Empty column; retained for backward compatibility with ColdFusion 5 applications on UNIX.You can use the following result columns in standard CFML expressions, preceding the result column name with the query name:
#mydirectory.name# #mydirectory.size# #mydirectory.type# #mydirectory.dateLastModified# #mydirectory.attributes# #mydirectory.mode#
Note: If the cfdirectory
tag does not appear to work, for example, if a list
operation returns an empty result set, make sure that you have correct permissions to access the directory. For example, if you run ColdFusion as a service on Windows, it operates by default as System, and cannot access directories on a remote system or mapped drive; to resolve this issue, do not run ColdFusion using the local system account.
The filter
attribute specifies a pattern of one or more characters. All names that match that pattern are included in the list. On Windows systems, pattern matching ignores text case, on UNIX and Linux, pattern matches are case-sensitive.
The following 2 characters have special meaning in the pattern and are called metacharacters:
The following table shows examples of patterns and file names that they match:
Pattern | Matches |
---|---|
foo.* |
any file called foo with any extention i.e. foo.html, foo.cfm, foo.xml, ... |
*.html |
all files with the suffix .html, but not files with the suffix .htm. |
?? |
all files with 2 character names. |
<h3>cfdirectory Example</h3> <!--- use cfdirectory to give the contents of the directory that contains
this page order by name and size ---> <cfdirectory directory="#GetDirectoryFromPath(GetTemplatePath())#" name="myDirectory" sort="name ASC, size DESC"> <!---- Output the contents of the cfdirectory as a cftable -----> <cftable query="myDirectory" htmltable colheaders> <cfcol header="NAME:" text="#Name#"> <cfcol header="SIZE:" text="#Size#"> </cftable>