relativePath
fn
string relativePath(CaseSensitive cs = CaseSensitive.osDefault)(string path, lazy string base = getcwd())Translates path into a relative path.
The returned path is relative to base, which is by default taken to be the current working directory. If specified, base must be an absolute path, and it is always assumed to refer to a directory. If path and base refer to the same directory, the function returns `.`.
The following algorithm is used:
- If
pathis a relative directory, return it unaltered. - Find a common root between
pathandbase.If there is no common root, return
pathunaltered. - Prepare a string with as many
`../`or`..\`asnecessary to reach the common root from base path.
- Append the remaining segments of
pathto the stringand return.
In the second step, path components are compared using filenameCmp!cs, where cs is an optional template parameter determining whether the comparison is case sensitive or not. See the
This function allocates memory.
Parameters
cs | Whether matching path name components against the base path should be case-sensitive or not. |
path | A path name. |
base | The base path to construct the relative path from. |
Returns
The relative path.
See Also
asRelativePath which does not allocate memory
Throws
Exception if the specified _base directory is not absolute.