Performing Directory Operations

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

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

Returning file information

When you use the action="list" attribute setting, cfdirectory returns five result columns that you can reference in a cfoutput tag:

To view directory information:

  1. Create a new file in ColdFusion Studio.
  2. Modify the file so that it appears as follows:
    <html>
    
    <head>
    
      <title>List Directory Information</title>
    
    </head>
    
    
    
    <body>
    
    <h2>List Directory Information</h2>
    
    <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>
    
    
  3. Modify the line directory="c:\inetpub\wwwroot\mine"so that it points to a directory on your server.
  4. Save the file as directoryinfo.cfm and view it in your browser.

Note that 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.



Banner.Novgorod.Ru