Path.hasAttributes

Check if file has numeric attributes. This method check if all bits specified by param 'attributes' are set.

struct Path
@safe const
bool
hasAttributes
(
in uint attributes
)

Parameters

attributes uint

numeric attributes (bit mask) to check

Return Value

Type: bool

true if all attributes present on file. false if at lease one bit specified by attributes is not set.

Examples

Example of checking attributes of file.

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!");

// Check that file has numeric permissions 644
root.join("test-file.txt").hasAttributes(octal!644).should.be(true);

// Check that it is not 755
root.join("test-file.txt").hasAttributes(octal!755).should.be(false);

// Check that every user can read this file.
root.join("test-file.txt").hasAttributes(octal!444).should.be(true);

// Check that owner can read the file
// (do not check access rights for group and others)
root.join("test-file.txt").hasAttributes(octal!400).should.be(true);

// Test that file is readable by user
root.join("test-file.txt").hasAttributes(S_IRUSR).should.be(true);

// Test that file is writable by user
root.join("test-file.txt").hasAttributes(S_IWUSR).should.be(true);

// Test that file is not writable by others
root.join("test-file.txt").hasAttributes(S_IWOTH).should.be(false);

Meta