Path.realPath

Get real path with all symlinks resolved. If any segment of path is symlink, then this method will automatically resolve that segment.

struct Path
version(Posix)
@trusted const
realPath
()

Return Value

Type: Path

Path with all symlinks resolved

Throws

ErrnoException in case if path cannot be resolved

Examples

import dshould;

Path root = createTempPath();
scope(exit) root.remove();

// Create test dir with content to test copying non-empty directory
root.join("test-dir").mkdir();
root.join("test-dir", "f1.txt").writeFile("f1");
root.join("test-dir", "d2").mkdir();
root.join("test-dir", "d2", "f2.txt").writeFile("f2");
root.join("test-dir", "d2").symlink(root.join("test-dir", "d3-s"));
root.join("test-dir", "d2", "f2.txt").symlink(
    root.join("test-dir", "f3.txt"));

// Test realpath
root.join("test-dir", "d3-s").realPath.should.equal(
    root.realPath.join("test-dir", "d2"));
root.join("test-dir", "f3.txt").realPath.should.equal(
    root.realPath.join("test-dir", "d2", "f2.txt"));
import dshould;

import std.exception: ErrnoException;

Path root = createTempPath();
scope(exit) root.remove();

// realpath on unexisting path must throw error
root.join("test-dir", "bad-path").realPath.should.throwA!ErrnoException;

Meta