View source code
Display the source code in std/path.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
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.
Function std.path.absolutePath
Transforms path
into an absolute path.
{null} absolutePath();
The following algorithm is used:
- If
path
is empty, returnnull
. - If
path
is already absolute, return it. - Otherwise, append
path
tobase
and return the result. Ifbase
is not specified, the current working directory is used.
Note that absolutePath
will not normalize ..
segments.
Use buildNormalizedPath(absolutePath(path))
if that is desired.
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)
{
writeln(absolutePath("some/file", "/foo/bar")); // "/foo/bar/some/file"
writeln(absolutePath("../file", "/foo/bar")); // "/foo/bar/../file"
writeln(absolutePath("/some/file", "/foo/bar")); // "/some/file"
}
version (Windows)
{
writeln(absolutePath(`some\file`, `c:\foo\bar`)); // `c:\foo\bar\some\file`
writeln(absolutePath(`..\file`, `c:\foo\bar`)); // `c:\foo\bar\..\file`
writeln(absolutePath(`c:\some\file`, `c:\foo\bar`)); // `c:\some\file`
writeln(absolutePath(`\`, `c:\`)); // `c:\`
writeln(absolutePath(`\some\file`, `c:\foo\bar`)); // `c:\some\file`
}
Authors
Lars Tandle Kyllingstad, Walter Bright, Grzegorz Adam Hankiewicz, Thomas Kühne, Andrei Alexandrescu
License
Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.