View source code Display the source code in std/file.d from which this page was generated on github. 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. Page wiki View or edit the community-maintained wiki page associated with this page.

Function std.file.isFile

Returns whether the given file (or directory) is a file.

On Windows, if a file is not a directory, then it's a file. So, either isFile or isDir will return true for any given file.

On Posix systems, if isFile 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 isFile and isDir to be false for a particular file (in which case, it's a special file). You can use getAttributes to get the attributes to figure out what type of special it is, or you can use DirEntry to get at its statBuf, which is the result from stat. In either case, see the man page for stat for more information.

Prototype

bool isFile(R)(
  R name
) @property
if (isInputRange!R && isSomeChar!(ElementEncodingType!R));

Parameters

NameDescription
name The path to the file.

Returns

true if name specifies a file

Throws

FileException if the given file does not exist.

Examples

assert("/etc/fonts/fonts.conf".isFile);
assert(!"/usr/share/include".isFile);

Authors

Walter Bright, Andrei Alexandrescu, Jonathan M Davis

License

Boost License 1.0.

Comments