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.isAbsolute
Determines whether a path is absolute or not.
Prototype
bool isAbsolute(R)( R path ) pure nothrow @safe if (isRandomAccessRange!R && isSomeChar!(ElementType!R) || is(StringTypeOf!R));
Parameters
| Name | Description |
|---|---|
| path | A path name. |
Returns
Whether a path is absolute or not.
Examples
On POSIX, an absolute path starts at the root directory.
(In fact, isAbsolute is just an alias for isRooted.)
version (Posix)
{
assert (isAbsolute("/"));
assert (isAbsolute("/foo"));
assert (!isAbsolute("foo"));
assert (!isAbsolute("../foo"));
}
On Windows, an absolute path starts at the root directory of
a specific drive. Hence, it must start with or d:\,
where d:/d is the drive letter. Alternatively, it may be a
network path, i.e. a path starting with a double (back)slash.
version (Windows)
{
assert (isAbsolute(d:\));
assert (isAbsolute(d:\foo));
assert (isAbsolute(\\foo\bar));
assert (!isAbsolute(\));
assert (!isAbsolute(\foo));
assert (!isAbsolute("d:foo"));
}
Authors
Lars Tandle Kyllingstad, Walter Bright, Grzegorz Adam Hankiewicz, Thomas Kühne, Andrei Alexandrescu