View source code
Display the source code in std/path.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Function std.path.absolutePath
Tranforms into an absolute path.
path
The following algorithm is used:
The function allocates memory if and only if it gets to the third stage of this algorithm.Prototype
string absolutePath( string path, string base = getcwd() ) pure @safe;
Parameters
| Name | Description |
|---|---|
| path | the relative path to transform |
| base | the base directory of the relative path |
Returns
string of transformed path
Throws
Exception if the specified base directory is not absolute.
See Also
asAbsolutePath which does not allocate
Example
version (Posix)
{
assert (absolutePath("some/file", "/foo/bar") == "/foo/bar/some/file");
assert (absolutePath("../file", "/foo/bar") == "/foo/bar/../file");
assert (absolutePath("/some/file", "/foo/bar") == "/some/file");
}
version (Windows)
{
assert (absolutePath(some\file, c:\foo\bar) == c:\foo\bar\some\file);
assert (absolutePath(..\file, c:\foo\bar) == c:\foo\bar\..\file);
assert (absolutePath(c:\some\file, c:\foo\bar) == c:\some\file);
assert (absolutePath(\, c:\) == c:\);
assert (absolutePath(\some\file, c:\foo\bar) == c:\some\file);
}
Authors
Lars Tandle Kyllingstad, Walter Bright, Grzegorz Adam Hankiewicz, Thomas Kühne, Andrei Alexandrescu