CFLib.org – Common Function Library Project

AddPathsToDirectoryQuery(theQuery[, basePath])

Last updated July 9, 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;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson