O'Reilly logo

Programming ColdFusion MX, 2nd Edition by Rob Brooks-Bilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Working with Directories

The cfdirectory tag lists directory contents and creates, renames, and deletes directories on your ColdFusion application server. In an application such as a document management system, the cfdirectory tag allows you to do such tasks as list all the documents stored in a particular folder or build a Windows Explorer-style view of files and folders on your server. Because the cfdirectory tag provides direct access to your ColdFusion server’s filesystem, it may represent a security concern depending on the nature of your server environment. If you wish, the tag can be disabled from the Sandbox Security section in the ColdFusion Administrator.

Listing Directory Contents

As just noted, the cfdirectory tag lists the contents of any directory on the ColdFusion server. Example 12-1 uses the cfdirectory tag to list the contents of the root directory on the C drive of the ColdFusion server.

Example 12-1. Listing a directory with cfdirectory

<cflock name="CLock" type="ReadOnly" timeout="30">
<cfdirectory action="List"
             directory="c:\"
             name="MyQuery"
             filter="*.*"
             sort="Type Asc, Name Asc">
</cflock>
   
<table border="1">
  <tr>
     <th>Name</th><th>Size</th><th>Type</th><th>Last Modified</th>
     <th>Attributes</th><th>Mode</th>
  </tr>
 
<cfoutput query="MyQuery">
  <tr>
     <td>#Name#</td><td>#Size#</td><td>#Type#</td><td>#DateLastModified#</td>
     <td>#Attributes#</td><td>#Mode#</td>
  </tr>
</cfoutput>             
</table>

The first attribute, action, tells ColdFusion what cfdirectory operation ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required