Path.join

Join multiple path segments and return single path.

  1. Path join(string[] segments)
  2. Path join(Path[] segments)
    struct Path
    const
    join

Parameters

segments Path[]

Array of strings (or Path) to build new path..

Return Value

Type: Path

New path build from current path and provided segments

Examples

import dshould;
string tmp_dir = createTempDirectory();
scope(exit) std.file.rmdirRecurse(tmp_dir);

auto ps = std.path.dirSeparator;

Path("tmp").join("test1", "subdir", "2").toString.should.equal(
    "tmp" ~ ps ~ "test1" ~ ps ~ "subdir" ~ ps ~ "2");

Path root = Path(tmp_dir);
root._path.should.equal(tmp_dir);
auto test_c_file = root.join("test-create.txt");
test_c_file._path.should.equal(tmp_dir ~ ps ~"test-create.txt");
test_c_file.isAbsolute.should.be(true);

version(Posix) {
    Path("/").join("test2", "test3").toString.should.equal("/test2/test3");
}

Meta