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, " ");

Attribute Reference for the cfdirectory tag

action

Required: No
Default: list
Action to perform Values:
  • list
  • create
  • delete
  • rename

directory

Required: Yes
Absolute pathname of directory against which to perform
action.

name

Required: No
Name for output record set.

filter

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

mode

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

sort

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

newdirectory

Required: No
New name for directory.

recurse

Required: No
Default: NO
Whether ColdFusion performs the action on subdirectories.

type

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

listinfo

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

Examples sample code using the cfdirectory tag


List Files in Directory (Script Syntax)

Returns a query

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

Create a Directory (Script Syntax)

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

Delete a Directory (Script Syntax)

Directory Delete

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

Rename a Directory (Script Syntax)

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

List File in Directory (Tag Syntax)

Directory List

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

Create a Directory (Tag Syntax)

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

Delete a Directory (Tag Syntax)

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

Rename a Directory (Tag Syntax)

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

Fork me on GitHub