CFLib.org – Common Function Library Project

AddPathsToDirectoryQuery(theQuery [, basePath])

Last updated July 9, 2003

Version: 1 | Requires: ColdFusion 5 | Library: FileSysLib

 
Rated 3 time(s). Average Rating: 2.7

Description:
Adds a "FullPath" column to provided directory query (from <cfdirectory action="LIST">). Handy for keeping track of what files were from where when combining directory queries from multiple directories.

Return Values:
query

Example:

view plain print about
<cfset dir = expandPath("./")>

<cfdirectory action="list" directory="#dir#" name="getFiles" filter="*.txt">
ORIGINAL QUERY:<br />
<cfdump var="#getFiles#">
<br /><br />
QUERY WITH NEW FullPath COLUMN:<br />
<cfset addPathsToDirectoryQuery (getFiles, dir)>
<cfdump var="#getFiles#">

Parameters:

Name Description Required
theQuery The query returned from CFDIRECTORY Yes
basePath String containing the path to the directory used in the CFDIRECTORY call No

Full UDF Source:

view plain print about
<cfscript>
/**
 * Adds a &quot;FullPath&quot; column to provided directory query.
 * 
 * @param theQuery      The query returned from CFDIRECTORY (Required)
 * @param basePath      String containing the path to the directory used in the CFDIRECTORY call (Optional)
 * @return query 
 * @author Shawn Seley (shawnse@aol.com) 
 * @version 1, July 9, 2003 
 */

function addPathsToDirectoryQuery(theQuery, basePath) {
    var row = 0;
    var new_col_array = arrayNew(1);

    if (listFindNoCase(theQuery.columnList, "FullPath")) {
        for(row=1; row LTE theQuery.recordCount; row=row+1) {
            querySetCell(theQuery, "FullPath", basePath & theQuery.name[row], row);
        }
    } else {
        for(row=1; row LTE theQuery.recordCount; row=row+1) {
            new_col_array[row] = basePath & theQuery.name[row];
        }
        queryAddColumn(theQuery, "FullPath", new_col_array);
    }

    return theQuery;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
12 day(s) ago

Will Belden Will Belden added
longTime
17 day(s) ago

James Sleeman James Sleeman added
quickSort
27 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
30 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson