View source code
Display the source code in std/path.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.path.isValidFilename

Checks that the given file or directory name is valid.

bool isValidFilename(Range) (
  Range filename
)
if ((isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && isSomeChar!(ElementEncodingType!Range) || isNarrowString!Range) && !isConvertibleToString!Range);

The maximum length of filename is given by the constant FILENAME_MAX. (On Windows, this number is defined as the maximum number of UTF-16 code points, and the test will therefore only yield strictly correct results when filename is a string of wchars.)

On Windows, the following criteria must be satisfied (source):

  • filename must not contain any characters whose integer representation is in the range 0-31.
  • filename must not contain any of the following reserved characters: <>:
  • filename may not end with a space (' ') or a period ('.').

On POSIX, filename may not contain a forward slash ('/') or the null character ('\0').

Parameters

NameDescription
filename string to check

Returns

true if and only if filename is not empty, not too long, and does not contain invalid characters.

Example

import std.utf : byCodeUnit;

assert(isValidFilename("hello.exe".byCodeUnit));

Authors

Lars Tandle Kyllingstad, Walter Bright, Grzegorz Adam Hankiewicz, Thomas Kühne, Andrei Alexandrescu

License

Boost License 1.0