CFLib.org – Common Function Library Project

UpDirLevel(currDir, upCt)

Last updated September 20, 2004

author

Joshua Miller

Version: 1 | Requires: CF5 | Library: FileSysLib

Description:
The UpDirLevel UDF climbs up a UNC Path a specified number of levels. I've found this useful when creating site management tools in one directory that affect files in another directory. You could return the ROOT of a path or use it to move to the directoy immediately above the current location.

Return Values:
Returns a string.

Example:

Root Location: <cfoutput>#upDirLevel('c:/inetpub/wwwroot',2)#</cfoutput>

Parameters:

Name Description Required
currDir The directory to use as a starting point from which to climb. Yes
upCt Integer specifying the number of directory levels to move up. Yes

Full UDF Source:

/**
 * Climbs up a given UNC Path a specified number of levels.
 * 
 * @param currDir 	 The directory to use as a starting point from which to climb. (Required)
 * @param upCt 	 Integer specifying the number of directory levels to move up. (Required)
 * @return Returns a string. 
 * @author Joshua Miller (josh@joshuasmiller.com) 
 * @version 1, September 20, 2004 
 */
function upDirLevel(currDir,upCt){
	var i=1;
	var currDirTemp=Reverse(currDir);
	var s=0;
	for(i=1;i LTE upCt;i=i+1){
		s=findoneof("\/",currDirTemp,1);
		if(s EQ 1){
			currDirTemp=Right(currDirTemp,val(Len(currDirTemp)-s));
			s=find("\",currDirTemp,1);
			currDirTemp=Right(currDirTemp,val(Len(currDirTemp)-s));
		}else{
			currDirTemp=Right(currDirTemp,val(Len(currDirTemp)-s));
		}
	}
	currDirTemp="#reverse(replacenocase(currDirTemp,'/','\','ALL'))#\";
	return currDirTemp;
}
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