Function std.path.buildPath
Combines one or more path segments.
immutable(ElementEncodingType!(ElementType!Range))[] buildPath(Range)
(
scope Range segments
)
if (isInputRange!Range && !isInfinite!Range && isSomeString!(ElementType!Range));
{null} buildPath(C)()
if (isSomeChar!C);
This function takes a set of path segments, given as an input
range of string elements or as a set of string arguments,
and concatenates them with each other. Directory separators
are inserted between segments if necessary. If any of the
path segments are absolute (as defined by isAbsolute
), the
preceding segments will be dropped.
On Windows, if one of the path segments are rooted, but not absolute
(e.g.
), all preceding path segments down to the previous
root will be dropped. (See below for an example.)
\foo
This function always allocates memory to hold the resulting path.
The variadic overload is guaranteed to only perform a single
allocation, as is the range version if paths
is a forward
range.
Parameters
Name | Description |
---|---|
segments | An input range of segments to assemble the path from. |
Returns
The assembled path.
Example
version (Posix)
{
writeln(buildPath("foo", "bar", "baz")); // "foo/bar/baz"
writeln(buildPath("/foo/", "bar/baz")); // "/foo/bar/baz"
writeln(buildPath("/foo", "/bar")); // "/bar"
}
version (Windows)
{
writeln(buildPath("foo", "bar", "baz")); // `foo\bar\baz`
writeln(buildPath(`c:\foo`, `bar\baz`)); // `c:\foo\bar\baz`
writeln(buildPath("foo", `d:\bar`)); // `d:\bar`
writeln(buildPath("foo", `\bar`)); // `\bar`
writeln(buildPath(`c:\foo`, `\bar`)); // `c:\bar`
}
Authors
Lars Tandle Kyllingstad, Walter Bright, Grzegorz Adam Hankiewicz, Thomas Kühne, Andrei Alexandrescu