Function std.path.isValidFilename
Checks that the given file or directory name is valid.
The maximum length of is given by the constant
filename. (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
core.stdc.stdio.FILENAME_MAX is a string of filenamewchars.)
On Windows, the following criteria must be satisfied (source):
must not contain any characters whose integer representation is in the range 0-31.filenamemust not contain any of the following reservedfilenamecharacters: <>:"/\|?*
may not end with a space (filename' ') or a period ('.').
On POSIX, may not contain a forward slash (filename'/') or
the null character ('\0').
Prototype
bool isValidFilename(Range)( Range filename ) if (is(StringTypeOf!Range) || isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && isSomeChar!(ElementEncodingType!Range));
Parameters
| Name | Description |
|---|---|
| filename | string to check |
Returns
true if and only if is not
empty, not too long, and does not contain invalid characters.
filename
Example
import std.utf : byCodeUnit; assert(isValidFilename("hello.exe".byCodeUnit));
Authors
Lars Tandle Kyllingstad, Walter Bright, Grzegorz Adam Hankiewicz, Thomas Kühne, Andrei Alexandrescu