View source code
Display the source code in std/file.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Function std.file.getAttributes
Returns the attributes of the given file.
uint getAttributes(R)
(
R name
)
if (isInputRange!R && !isInfinite!R && isSomeChar!(ElementEncodingType!R) && !isConvertibleToString!R);
uint getAttributes(R)
(
auto ref R name
)
if (isConvertibleToString!R);
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.
Parameters
Name | Description |
---|---|
name | The file to get the attributes of. |
Returns
The attributes of the file as a uint
.
Throws
FileException
on error.
Example
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);
Example
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);
Authors
License
Copyright © 1999-2018 by the D Language Foundation | Page generated by ddox.