ColdFusion UDF Library - pathToRelative
December 16th, 2008
«« Back to ColdFusion Library
Category:
SYSTEM
Description:
Converts a full path to a relative one.
Parameters:
Returns:
(String) This function returns a relative path.
Requires:
listDiff(), listMid()
Sample Use:
Copy to Clipboard
Category:
SYSTEM
Description:
Converts a full path to a relative one.
Parameters:
- path (String, required)
The fullpath to convert to relative. - path2 (String, Default: (current directory))
The path to find a relationship with the first path. Default (current directory).
Returns:
(String) This function returns a relative path.
Requires:
listDiff(), listMid()
Sample Use:
Copy to Clipboard
/* #depends:listDiff,listMid# */
function pathToRelative(path){
var backPeddle = 0;
var path2 = getDirectoryFromPath(getBaseTemplatePath());
var value = "";
var diff = 0;
if (arrayLen(arguments) gte 2)path2 = arguments[2];
diff = server.listDiff(path,path2,1,"\","\");
if (not arrayLen(diff))diff = 0;
backPeddle = listLen(path2,"\")-diff+1;
value = repeatString("../",backPeddle) & listChangeDelims(server.listMid(path,backPeddle+1,(listLen(path,"\")-backPeddle),"\"),"/","\") & "/";
return value;
}
// http://www.programmers.org/index.php/coldfusion-udf-library/?ckey=99&function=pathToRelative



