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.isValidPath
Checks whether path is a valid path.
						
				bool isValidPath(Range)
				(
				
				  Range path
				
				)
				
				if ((isRandomAccessRange!Range && hasLength!Range && hasSlicing!Range && isSomeChar!(ElementEncodingType!Range) || isNarrowString!Range) && !isConvertibleToString!Range);
						
					
				Generally, this function checks that path is not empty, and that
    each component of the path either satisfies isValidFilename
    or is equal to "." or "..".
    It does not check whether the path points to an existing file
    or directory; use exists for this purpose.
On Windows, some special rules apply:
- If the second character of pathis a colon (':'), the first character is interpreted as a drive letter, and must be in the range A-Z (case insensitive).
- If pathis on the form\\class="pln">I server\class="pln">I share\...isValidFilenameis applied to server and share as well.
- If pathstarts with\\?\
- If pathstarts with\\.\ false; such paths are beyond the scope of this module.
Parameters
| Name | Description | 
|---|---|
| path | string or Range of characters to check | 
Returns
true if path is a valid path.
Example
assert(isValidPath("/foo/bar"));
assert(!isValidPath("/foo\0/bar"));
assert(isValidPath("/"));
assert(isValidPath("a"));
version (Windows)
{
    assert(isValidPath(`c:\`));
    assert(isValidPath(`c:\foo`));
    assert(isValidPath(`c:\foo\.\bar\\\..\`));
    assert(!isValidPath(`!:\foo`));
    assert(!isValidPath(`c::\foo`));
    assert(!isValidPath(`c:\foo?`));
    assert(!isValidPath(`c:\foo.`));
    assert(isValidPath(`\\server\share`));
    assert(isValidPath(`\\server\share\foo`));
    assert(isValidPath(`\\server\share\\foo`));
    assert(!isValidPath(`\\\server\share\foo`));
    assert(!isValidPath(`\\server\\share\foo`));
    assert(!isValidPath(`\\ser*er\share\foo`));
    assert(!isValidPath(`\\server\sha?e\foo`));
    assert(!isValidPath(`\\server\share\|oo`));
    assert(isValidPath(`\\?\<>:"?*|/\..\.`));
    assert(!isValidPath("\\\\?\\foo\0bar"));
    assert(!isValidPath(`\\.\PhysicalDisk1`));
    assert(!isValidPath(`\\`));
}
import stdAuthors
Lars Tandle Kyllingstad, Walter Bright, Grzegorz Adam Hankiewicz, Thomas Kühne, Andrei Alexandrescu
License
					Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.