CFLib.org – Common Function Library Project

AddPathsToDirectoryQuery(theQuery[, basePath])

Last updated July 09, 2003

author

Shawn Seley

Version: 1 | Requires: CF5 | Library: FileSysLib

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:

<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:

/**
 * 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;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson