getAttributes

Returns the attributes of the given file.

Note that the file attributes on Windows and POSIX systems are completely different. On Windows, they're what is returned by GetFileAttributes, whereas on POSIX systems, they're the st_mode value which is part of the stat struct gotten by calling the stat function.

On POSIX systems, if the given file is a symbolic link, then attributes are the attributes of the file pointed to by the symbolic link.

  1. uint getAttributes(R name)
  2. uint getAttributes(R name)
    uint
    getAttributes
    (
    R
    )
    (
    auto ref R name
    )

Parameters

name R

The file to get the attributes of.

Return Value

Type: uint

The attributes of the file as a uint.

Throws

FileException on error.

Examples

getAttributes with a file

import std.exception : assertThrown;

auto f = deleteme ~ "file";
scope(exit) f.remove;

assert(!f.exists);
assertThrown!FileException(f.getAttributes);

f.write(".");
auto attributes = f.getAttributes;
assert(!attributes.attrIsDir);
assert(attributes.attrIsFile);

getAttributes with a directory

import std.exception : assertThrown;

auto dir = deleteme ~ "dir";
scope(exit) dir.rmdir;

assert(!dir.exists);
assertThrown!FileException(dir.getAttributes);

dir.mkdir;
auto attributes = dir.getAttributes;
assert(attributes.attrIsDir);
assert(!attributes.attrIsFile);

Meta