CFDIRECTORY


CFDIRECTORY

We've examined how CFFTP enables you to manage files on a remote server through the FTP protocol from within your ColdFusion applications. Earlier in this text, we also discussed how you can use CFFILE to work directly with files that exist on your ColdFusion Server. Now, suppose you want to enable your ColdFusion application to work with the directories on your server as well. With CFDIRECTORY, you can easily give your applications the ability to list, create, rename, and delete directories on your server.

Table 12.4 examines the CFDIRECTORY tag and its attributes.

Table 12.4. CFDIRECTORY Attributes

Attribute

Description

action

This attribute is optional, and it specifies the type of action that you'd like CFDIRECTORY to perform.

Valid actions for the CFDIRECTORY tag are as follows:

  • create

  • delete

  • list

  • rename

If no action is specified, the CFDIRECTORY tag defaults to list, performing a listing of the specified directory.

directory

This is a required attribute that enables you to specify the name of the directory on which you would like to perform the specified action. You should always end any directory attribute value with a slash.

filter

This is an optional attribute, which should be used when the action is set to list. The filter attribute enables you to apply a file extension filter to your directory listing so that only those files meeting the specified criteria are returned.

As an example, if you were listing a directory of images and only wanted Graphics Interchange Format (GIF) files returned, you would use "*.gif" in the filter attribute to specify that only those files matching that criteria should be returned to you.

mode

The attribute is an optional attribute that is useful on UNIX or Linux platforms when the action is set to create. This attribute lets you set permissions on the directory that you are creating.

Valid modes are as follows:

  • 644. Sets read/write permissions for the owner and read permissions for group and other.

  • 666. Sets read/write permissions for the owner, group, and other.

  • 777. Sets read/write/execute permissions for all.

name

This attribute is required when the action is set to list. This attribute names your directory listing so that you know what variable to call when you want to display the output query.

For example, if you named your directory listing MyListing,you would use <cfoutput query="MyListing"> to display the results of that directory list.

newdirectory

This attribute is required when the action is set to rename. This attribute enables you to specify the new name you want to use for the directory that you are renaming.

sort

This is an optional attribute that can be used when the action is set to list. This attribute enables you to specify the query columns on which you would like to sort, either ascending or descending.

The following example shows CFDIRECTORY performing a simple directory listing on a specified directory:

 <html>    <head>      <title>Example of &lt;cfdirectory&gt; Usage</title>    </head>  <body>  <!--- use cfdirectory to display a directory listing --->  <cfset variables.webdrive = ListFirst(ExpandPath("."),  /\")>  <cfoutput>#variables.webdrive#<br></cfoutput>  <cfdirectory directory="#variables.webdrive#/"               name="myTempFiles"               sort="name ASC">  <!--- output the results --->  <cfoutput query="myTempFiles">  #name#<br>  </cfoutput>  </body>  </html> 

As with CFFTP, the example here is a simple directory listing to give you the idea of syntax and simple usage. The CFDIRECTORY tag itself, however, is much more powerful, enabling you to sort, delete, create, and rename. This opens the power of the file system to your ColdFusion application for file management purposes.

For a complete description of all CFDIRECTORY actions and syntax, refer to Appendix B.



Inside ColdFusion MX
Inside Coldfusion MX
ISBN: 0735713049
EAN: 2147483647
Year: 2005
Pages: 579

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net