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.attrIsFile

Returns whether the given file attributes are for a file.

bool attrIsFile (
  uint attributes
) pure nothrow @nogc @safe;

On Windows, if a file is not a directory, it's a file. So, either attrIsFile or attrIsDir will return true for the attributes of any given file.

On Posix systems, if attrIsFile is true, that indicates that the file is a regular file (e.g. not a block not device). So, on Posix systems, it's possible for both attrIsFile and attrIsDir to be false for a particular file (in which case, it's a special file). If a file is a special file, you can use the attributes to check what type of special file it is (see the man page for stat for more information).

Parameters

NameDescription
attributes The file attributes.

Returns

true if the given file attributes are for a file

Example

assert(attrIsFile(getAttributes("/etc/fonts/fonts.conf")));
assert(attrIsFile(getLinkAttributes("/etc/fonts/fonts.conf")));

Example

import std.exception : assertThrown;

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

dir.mkdir;
assert(!dir.isFile);
assert(!dir.getAttributes.attrIsFile);

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

f.write(".");
assert(f.isFile);
assert(f.getAttributes.attrIsFile);

Authors

Walter Bright, Andrei Alexandrescu, Jonathan M Davis

License

Boost License 1.0.