isRooted

Determines whether a path starts at a root directory.

bool
isRooted
(
R
)
()
if (
isRandomAccessRange!R &&
isSomeChar!(ElementType!R)
||
is(StringTypeOf!R)
)

Parameters

path R

A path name.

Return Value

Type: bool

Whether a path starts at a root directory.

On POSIX, this function returns true if and only if the path starts with a slash (/).

On Windows, this function returns true if the path starts at the root directory of the current drive, of some other drive, or of a network drive.

Examples

version (Posix)
{
    assert( isRooted("/"));
    assert( isRooted("/foo"));
    assert(!isRooted("foo"));
    assert(!isRooted("../foo"));
}

version (Windows)
{
    assert( isRooted(`\`));
    assert( isRooted(`\foo`));
    assert( isRooted(`d:\foo`));
    assert( isRooted(`\\foo\bar`));
    assert(!isRooted("foo"));
    assert(!isRooted("d:foo"));
}

Meta