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"
             sort="Type Asc, Name Asc">
<table border="1">
     <th>Name</th><th>Size</th><th>Type</th><th>Last Modified</th>
<cfoutput query="MyQuery">

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

Get Programming ColdFusion MX, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.