Use the cfdirectory tag to return file information from a specified directory and to create, delete, and rename directories. When listing directory contents or deleting a directory, you can optionally use the recurse attribute to access or delete all subdirectories.
As with the cffile tag, you can disable cfdirectory processing in the ColdFusion Administrator. For details on the syntax of this tag, see the CFML Reference.

Returning file information

When you use the action="list" attribute setting, the cfdirectory returns a query object as specified in the name attribute. The name attribute is required when you use the action="list" attribute setting. This query object contains result columns that you can reference in a cfoutput tag, using the value specified in the name attribute:

  • name Directory entry name.
  • directory Directory containing the entry.
  • size Directory entry size.
  • type File type: File or Dir.
  • dateLastModified Date an entry was last modified.
  • attributes (Windows only) File attributes, if applicable.
  • mode(UNIX only) The octal value representing the permissions setting for the specified directory.

    Note: ColdFusion supports the ReadOnly and Hidden values for the attributes attribute for cfdirectory sorting.

    Depending on whether your server is on a UNIX system or a Windows system, either the Attributes column or the Mode column is empty. Also, you can specify a filename in the filter attribute to get information on a single file.The following procedure describes how to create a ColdFusion page in which to view directory information.

View directory information
  1. Create a ColdFusion page with the following content:

    <title>List Directory Information</title>

    <h3>List Directory Information</h3>
    sort="size ASC, name DESC, datelastmodified">

    <table cellspacing=1 cellpadding=10>
    <cfoutput query="mydirectory">


  2. Modify the path C:\inetpub\wwwroot\mine so that it points to a directory on your server.
  3. Save the file as directoryinfo.cfm in the myapps directory under your web_root and view it in the browser.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy