cfdirectory

Allows you to list, create, delete or rename a directory in the server file system.

  <cfdirectory directory="." action="list|create|delete|rename">

 directoryList(".", false, " ");

cfdirectory Attribute Reference

action string
Default: list

Action to perform
Values:
  • list
  • create
  • delete
  • rename

directory string
Required

Absolute pathname of directory against which to perform
action.

name string

Name for output record set.

filter string

File extension filter applied to returned names. For
example: *.cfm. One filter can be applied.

mode string

Applies only to UNIX and Linux. Permissions. Octal values
of Unix chmod command. Assigned to owner, group, and
other, respectively.

sort string
Default: asc

Query column(s) by which to sort directory listing.
Delimited list of columns from query output.
Values:
  • asc
  • desc

newdirectory string

New name for directory.

recurse boolean
Default: false

Whether ColdFusion performs the action on subdirectories.
Values:
  • true
  • false

type string
Default: all

* file: includes only filenames.
* dir: includes only directory names.
* all: includes both filenames and directory names.
Values:
  • dir
  • file
  • all

listinfo string
Default: all

* all: includes all information in the result set.
* name: includes only filenames in the result set.
Values:
  • name
  • all

Compatibility

Lucee:

In Lucee the filter param can be a closure as well where the path is passed in. It seems that there is no way to access the file query. If a directory returns false in recursive mode the contained files are processed anyways

Links more information about cfdirectory

Examples sample code using the cfdirectory tag

Returns a query

myList = directoryList(expandPath("./"), false, "query");

directoryCreate(expandPath("./new_directory"));

Directory Delete

directoryDelete(expandPath("./my_directory"));

directoryRename(expandPath("./my_directory"), expandPath("./new_driectory"));

Directory List

<cfdirectory action="list" directory="#expandPath("./")#" recurse="false" name="myList">

<cfdirectory action="create" directory="#expandPath("./new_directory")#">

<cfdirectory action="delete" directory="#expandPath("./my_directory")#">

<cfdirectory action="rename" directory="#expandPath("./my_directory")#" newdirectory="#expandPath("./new_directory")#">

Fork me on GitHub