2.1.4.15 BuildRelativeName -- Algorithm for Building the Relative Path Name for a Link
The inputs for this algorithm are:
Link: A Link whose relative path name we are building.
RootDirectory: A DirectoryFile indicating how far to walk up the directory hierarchy when building the relative path name.
This algorithm returns a Unicode string representing the portion of a Link's path name from RootDirectory to Link itself, inclusive. The returned string starts with a backslash and uses backslashes as path separators. If Link is not a descendant of RootDirectory, the algorithm returns an empty string to indicate this error.
Pseudocode for the algorithm is as follows:
If Link.File equals RootDirectory:
Return "\".
Else If Link.File equals Link.File.Volume.RootDirectory:
Return an empty string.
Else If Link.ParentFile equals RootDirectory:
Return "\" + Link.Name.
Else
Set ParentRelativeName to BuildRelativeName(Link.ParentFile, RootDirectory).
If ParentRelativeName is empty:
Return an empty string.
Else
Return ParentRelativeName + "\" + Link.Name.
EndIf
EndIf