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.driveName
Get the drive portion of a path.
auto auto driveName(R)
(
R path
)
if (isRandomAccessRange!R && hasSlicing!R && hasLength!R && isSomeChar!(ElementType!R) && !isSomeString!R);
auto auto driveName(C)
(
C[] path
)
if (isSomeChar!C);
Parameters
Name | Description |
---|---|
path | string or range of characters |
Returns
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.
Example
import std .range : empty;
version (Posix) assert(driveName("c:/foo") .empty);
version (Windows)
{
assert(driveName(`dir\file`) .empty);
writeln(driveName(`d:file`)); // "d:"
writeln(driveName(`d:\file`)); // "d:"
writeln(driveName("d:")); // "d:"
writeln(driveName(`\\server\share\file`)); // `\\server\share`
writeln(driveName(`\\server\share\`)); // `\\server\share`
writeln(driveName(`\\server\share`)); // `\\server\share`
static assert(driveName(`d:\file`) == "d:");
}
Authors
Lars Tandle Kyllingstad, Walter Bright, Grzegorz Adam Hankiewicz, Thomas Kühne, Andrei Alexandrescu
License
Copyright © 1999-2018 by the D Language Foundation | Page generated by ddox.