CFX_ListDir
Windows only

v1.0

January 2007


© Claude Schnéegans

DESCRIPTION
INSTALLATION
SYNTAX
EXAMPLE

DESCRIPTION

This tag is a working replacement for <CFDIRECTORY ACTION="list" ... >
The results returned by CFDIRECTORY are far from being complete and useful:

CFX_ListDir is an attempt to fix these flaws, and to give more accurate and detailed information, in a consistent way under any CF version (It was not tested for CF 4, but there is no reason it should not work as well).

The main feature in CFX_ListDir are:

(see example below).

INSTALLATION

Installing the custom tag

To use this tag, you need to take the included CFX_ListDir.dll, install it on a drive on your server and make it known to the ColdFusion administrator.

You do this by going to the "CFX Tags" tab in the administrator,

  1. click the "add" button.
  2. Specify the name as CFX_ListDir.
  3. For the Server library(dll), specify the path to the .dll (the directory into which you copied CFX_ListDir.dll.
  4. It should say for "Procedure", "ProcessTagRequest".

That's it!

For more information refer to the ColdFusion documentation "Managing CFXs".

Installing documentation

Install the .cfm files in any convenient directory on your server. To view the documentation, load ListDirDoc.cfm into your browser.

SYNTAX

<CFX_ListDir 
    DIRECTORY = <full path name of the directory to list">
    [NAME] = <Name for output record set.>
    [QUERY] = <Name of an optional query to append results to.>
    [FILTER] = <File extension filter applied to returned names;>
    [EXTENSIONS] = <List of file extensions>
    [MODIFIEDBEFORE] = <limit file list to those modified before this date>
    [MODIFIEDAFTER] = <limit file list to those modified after this date>
    [TYPE] = <file or dir, to list only files or directories>
    [READONLY] = <select files according to their read-only attribute>
    [SYSTEM] = <select files according to their system attribute>
    [HIDDEN] = <select files according to their hidden attribute>
    [ARCHIVE] = <select files according to their archive attribute>
    [RECURSE] = <Whether the tag performs the action on subdirectories>
    [SORT] = <Query column(s) by which to sort directory listing>
    >

TAG ATTRIBUTE CONTENT REQUIRED DEFAULT
<CFX_ListDir DIRECTORY= Full path name of the directory to list. (ex: C:\inetsrv\wwwroot) Yes N/A
NAME= Name of the query to be returned by CFX_ListDir. No "listDir"
QUERY= If this attribute is supplied, and it contains a query compatible with queries generated by CFX_ListDir, the record set will be appended to this query and no new query will be created. Use this attribute to create a larger query containing list of files in several independant directories.

Furthermore, one can call the tag with only the NAME attribute, and QUERY set to an empty string. This will just create an empty query with all appropriate columns, and this query may be used later to append new record set to it (see last example below).

No "listDir"
FILTER= File extension filter applied to returned names; for example, *.cfm. One filter can be applied. Use attribute EXTENSION for an alternative way to select file names. The filter may use wildcard characters like ? or *. No "*.*"
EXTENSIONS= Comma separated list of file extension to be used as filter on file names. Ex: "cfm,css,htm,html,js". Notes:
  1. Do not include the dot before the extension;
  2. The extension may NOT include wildcards.
  3. The attribute FILTER may be used in conjunction with EXTENSIONS, and will be applied first.
No ""
MODIFIEDBEFORE= Use this attribute to provide a date to select only files modified before this date. The date must be supplied in ODBCDateTime format, not just ODBCDate (see CreateODBCDateTime () function). No ""
MODIFIEDAFTER= Use this attribute to provide a date to select only files modified after this date. The date must be supplied in ODBCDateTime format, not just ODBCDate (see CreateODBCDateTime () function). No N/A
TYPE="file|dir" Use this attribute with values "file" or "dir" to limite output to files only or directories only respectively. No ""
READONLY="yes|no" With READONLY="yes", the tag will only list files having the read-only attribute set.
With READONLY="no", the tag will only list files having the read-only attribute NOT set.
No N/A
SYSTEM="yes|no" With SYSTEM="yes", the tag will only list files having the system attribute set.
With SYSTEM="no", the tag will only list files having the system attribute NOT set.
No N/A
HIDDEN="yes|no" With HIDDEN="yes", the tag will only list files having the hidden attribute set.
With HIDDEN="no", the tag will only list files having the hidden attribute NOT set.
No N/A
ARCHIVE="yes|no" With ARCHIVE="yes", the tag will only list files having the archive attribute set.
With ARCHIVE="no", the tag will only list files having the archive attribute NOT set.
No N/A
RECURSE Whether ColdFusion performs the action on subdirectories. Only the presence of the attribute is needed, for instance, with RECURSE="no", the tag will still perform recursively. No N/A
SORT= This is a list of a maximum of two columns that may be used to sort the query. Any column may be used. The sort is alway in ascending order, no ASC or DESC modifier may be used. No ""

COLUMNS RETUNED BY THE QUERY
Column Name Description of Content
Name Name of the File or directory; Ex: myTemplate.cfm (CFDIRECTORY compatible).
directory Full path name of the directory in which the file is; Ex: C:\inetsrv\wwwroot\MySite (CFDIRECTORY compatible).
size Size of the file in bytes, or 0 for a directory (CFDIRECTORY compatible).
type Either "File" for a file, or "Dir" for a directory (CFDIRECTORY compatible).
readOnly Either "Yes" or "no", according to the corresponding file attribute (Addition to CFDIRECTORY).
System Either "Yes" or "no", according to the corresponding file attribute (Addition to CFDIRECTORY).
Hidden Either "Yes" or "no", according to the corresponding file attribute (Addition to CFDIRECTORY).
Archive Either "Yes" or "no", according to the corresponding file attribute (Addition to CFDIRECTORY).
dateLastModified Date the file was last modified, in full ODBCDateTime format; Ex: {ts '2004-02-02 14:11:57'} (Improvement to CFDIRECTORY)
dateCreated Date the file was created, in full ODBCDateTime format; Ex: {ts '2004-02-02 14:11:57'} (Addition to CFDIRECTORY).
dateLastAccess Date the file was last accessed, in full ODBCDateTime format; Ex: {ts '2004-02-02 14:11:57'} (Addition to CFDIRECTORY).

EXAMPLES

List all source files in project "CustomTags", sorted by directory an name

<CFX_LISTDIR 
  DIRECTORY="C:\inetsrv\wwwroot\CustomTags" 
  NAME="getDir" 
  SORT="directory,name" 
  RECURSE
  EXTENSIONS="cfm,css,htm,html,js"
  >

List all source files in project "CustomTags" last modified before one year ago, sorted by dateLastModified

<CFX_LISTDIR 
  DIRECTORY="C:\inetsrv\wwwroot\CustomTags" 
  NAME="getDir" 
  SORT="dateLastModified" 
  RECURSE
  EXTENSIONS="cfm,css,htm,html,js"
  MODIFIEDAFTER="#CreateODBCDate (dateAdd ("YYYY", -1, now()))#"
  >

List all read-only files in project "CustomTags"

<CFX_LISTDIR 
  DIRECTORY="C:\inetsrv\wwwroot\CustomTags" 
  READONLY="yes"
  RECURSE
  >

List all CFM files in several directories in only one query

<!--- Create an empty query "getDir" --->
<CFX_LISTDIR QUERY="" NAME="getDir">

<!--- Append files from mapClick --->
<CFX_LISTDIR QUERY="getDir"
    FILTER="*.cfm"
    DIRECTORY="C:\inetsrv\wwwroot\CustomTags\mapClick">
    
<!--- Append files from mapData --->
<CFX_LISTDIR QUERY="getDir"
    FILTER="*.cfm"
    DIRECTORY="C:\inetsrv\wwwroot\CustomTags\mapData">
    
<!--- Append files from stampImage --->
<CFX_LISTDIR QUERY="getDir"
    FILTER="*.cfm"
    DIRECTORY="C:\inetsrv\wwwroot\CustomTags\stampImage">
See other cool tags by
See other cool tags