Path.getAttributes

Get attributes of the path

struct Path
const
getAttributes
()

Return Value

Type: auto

uint - represening attributes of the file

Examples

Test if file has permission to run

import dshould;
import std.conv: octal;
Path root = createTempPath();
scope(exit) root.remove();

// Here we have to import bitmasks from system;
import core.sys.posix.sys.stat;

root.join("test-file.txt").writeFile("Hello World!");
auto attributes = root.join("test-file.txt").getAttributes();

// Test that file has permissions 644
(attributes & octal!644).should.equal(octal!644);

// Test that file is readable by user
(attributes & S_IRUSR).should.equal(S_IRUSR);

// Test that file is not writeable by others
(attributes & S_IWOTH).should.not.equal(S_IWOTH);

Meta