APGen Documentation Previous Topic: Util.ConcatPath() Next Topic: Util.OpenFileDialog() Parent Topic: Util Object    Util Object
Util.BuildRelativePath()
See Also:

The Util.BuildRelativePath() method computes a relative path from one path to another path.

Syntax

VBScript:

strRelPath = Util.BuildRelativePath( strPathFrom, strPathTo [, bPathFromIsDir] )

JScript:

strRelPath = Util.BuildRelativePath( strPathFrom, strPathTo [, bPathFromIsDir] );
Object

Util The Util object.

Parameters

strPathFrom The starting path.
strPathTo The destination path.
bPathFromIsDir Optional.  Specify True if strPathFrom is known to be a directory.  The default value is False.
True: strPathFrom is a directory.

False: strPathFrom is a directory only if it ends with a slash.  Otherwise it is a file.

Return Value

strRelPath Combining strPathFrom with this value equals strPathTo.

Notes

The return value strRelPath uses the same type of slashes (forward slashes, or backslashes) as strPathTo.

Util.BuildRelativePath() builds the relative path by finding identical path segments at the beginning of both strPathFrom and strPathTo.  The comparison of path segments is case-insensitive. 

Util.BuildRelativePath() assumes that strPathFrom and strPathTo are on the same volume.  This allows combination of partial paths, so that

Util.BuildRelativePath("subdir1\", "subdir2\")

returns "..\subdir2\".  If strPathFrom and strPathTo are full paths on different drives, you may receive an invalid return value.  We recommend that you ensure that strPathFrom and strPathTo are on the same drive before calling Util.BuildRelativePath().

Example Result Sets

Following are some example result sets for Util.BuildRelativePath().

strPathFrom "\prj\web\site\content\products\"
strPathTo "/prj/web/site/drop/products/default.htm"
strRelPath "../../drop/products/default.htm"

strPathFrom "\prj\web\site\content\products"
strPathTo "/prj/web/site/drop/products/default.htm"
bPathFromIsDir True
strRelPath "../../drop/products/default.htm"

strPathFrom "\prj\web\site\content\products"
strPathTo "/prj/web/site/drop/products/default.htm"
bPathFromIsDir False
strRelPath "../drop/products/default.htm"

strPathFrom "c:\Program Files\APGen\bin\APGen.exe"
strPathTo "c:\Util\apg scripts\script.apg"
strRelPath "..\..\..\Util\apg scripts\script.apg"

Example

This example computes the relative path to an image file for a HTML IMG tag.  The relative path is computed using Output.Path as strPathFrom, which will make the image viewable in the resulting web page.

<%#

...
Dim sImgPath
sImgPath = "c:/prj/web/drop/img/logo.gif"

#%>
<IMG src="
<%# =Util.BuildRelativePath(Output.Path, sImgPath) #%>" >
...

Applies To

Util Object