View comments | RSS feed

Using cfdirectory

Use the cfdirectory tag to return file information from a specified directory and to create, delete, and rename directories.

As with cffile, you can disable cfdirectory processing in the ColdFusion Administrator. For details on the syntax of this tag, see CFML Reference.

Returning file information

When you use the action="list" attribute setting, 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 five result columns that you can reference in a cfoutput tag, using the name attribute:

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.

To view directory information:

  1. Create a ColdFusion page with the following content:
    <html>
    <head>
      <title>List Directory Information</title>
    </head>
    
    <body>
    <h3>List Directory Information</h3>
    <cfdirectory
      directory="c:\inetpub\wwwroot\mine"
      name="mydirectory"
      sort="size ASC, name DESC, datelastmodified">
    
    <table cellspacing=1 cellpadding=10>
    <tr>
      <th>Name</th>
      <th>Size</th>
      <th>Type</th>
      <th>Modified</th>
      <th>Attributes</th>
      <th>Mode</th>
    </tr>
    <cfoutput query="mydirectory">
    <tr>
      <td>#mydirectory.name#</td>
      <td>#mydirectory.size#</td>
      <td>#mydirectory.type#</td>
      <td>#mydirectory.dateLastModified#</td>
      <td>#mydirectory.attributes#</td>
      <td>#mydirectory.mode#</td>
    </tr>
    </cfoutput>
    </table>
    
    </body>
    </html>
    
  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:

    Results of viewing directoryinfo.cfm in a browser.

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6

Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.

Comments


DanDuzWDD said on Mar 7, 2004 at 9:33 PM :
Is there some way to tell if an entry in the resulting record set of a cfdirectory is a file or a folder?
I tried a couple of things and one always said it was a file and the other always a folder.
What would happen if I tried to get a directory from a file, because of not being able to decide the difference?
halL said on Mar 8, 2004 at 6:23 AM :
Each row in the recordset contains a type field which is either File or Dir to indicate whether the entry is a File or Directory.
The example on this page shows this, but the directory that was listed didn't have any subdirectories.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6/Developing_ColdFusion_MX_Applications_with_CFML/manageFiles4.htm