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

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