driveName

Get the drive portion of a path.

  1. auto driveName(R path)
    driveName
    (
    R
    )
    ()
    if (
    isRandomAccessRange!R &&
    hasSlicing!R
    &&
    hasLength!R
    &&
    isSomeChar!(ElementType!R)
    &&
    )
  2. auto driveName(C[] path)

Parameters

path R

string or range of characters

Return Value

Type: auto

A slice of path that is the drive, or an empty range if the drive is not specified. In the case of UNC paths, the network share is returned.

Always returns an empty range on POSIX.

Examples

import std.range : empty;
version (Posix)  assert(driveName("c:/foo").empty);
version (Windows)
{
    assert(driveName(`dir\file`).empty);
    assert(driveName(`d:file`) == "d:");
    assert(driveName(`d:\file`) == "d:");
    assert(driveName("d:") == "d:");
    assert(driveName(`\\server\share\file`) == `\\server\share`);
    assert(driveName(`\\server\share\`) == `\\server\share`);
    assert(driveName(`\\server\share`) == `\\server\share`);

    static assert(driveName(`d:\file`) == "d:");
}

Meta