This module is used to manipulate path strings.
All functions, with the exception of expandTilde (and in some cases absolutePath and relativePath), are pure string manipulation functions; they don't depend on any state outside the program, nor do they perform any actual file system actions. This has the consequence that the module does not make any distinction between a path that points to a directory and a path that points to a file, and it does not know whether or not the object pointed to by the path actually exists in the file system. To differentiate between these cases, use std.file.isDir and std.file.exists.
Note that on Windows, both the backslash (`\`) and the slash (`/`) are in principle valid directory separators. This module treats them both on equal footing, but in cases where a new separator is added, a backslash will be used. Furthermore, the buildNormalizedPath function will replace all slashes with backslashes on that platform.
In general, the functions in this module assume that the input paths are well-formed. (That is, they should not contain invalid characters, they should follow the file system's path format, etc.) The result of calling a function on an ill-formed path is undefined. When there is a chance that a path or a file name is invalid (for instance, when it has been input by the user), it may sometimes be desirable to use the isValidFilename and isValidPath functions to check this.
Most functions do not perform any memory allocations, and if a string is returned, it is usually a slice of an input string. If a function allocates, this is explicitly mentioned in the documentation.
|Normalization||absolutePath asAbsolutePath asNormalizedPath asRelativePath buildNormalizedPath buildPath chainPath expandTilde|
|Partitioning||baseName dirName dirSeparator driveName pathSeparator pathSplitter relativePath rootName stripDrive|
|Validation||isAbsolute isDirSeparator isRooted isValidFilename isValidPath|
|Extension||defaultExtension extension setExtension stripExtension withDefaultExtension withExtension|
|Other||filenameCharCmp filenameCmp globMatch CaseSensitive|
This enum is used as a template argument to functions which compare file names, and determines whether the comparison is case sensitive or not.
Transforms path into an absolute path.
Transforms path into an absolute path.
Normalize a path by resolving current/parent directory symbols ("." and "..") and removing superfluous directory separators. It will return "." if the path leads to the starting directory. On Windows, slashes are replaced with backslashes.
Transforms path into a path relative to base.
Performs the same task as buildPath, while at the same time resolving current/parent directory symbols ("." and "..") and removing superfluous directory separators. It will return "." if the path leads to the starting directory. On Windows, slashes are replaced with backslashes.
Combines one or more path segments.
Concatenate path segments together to form one path.
Returns the parent directory of path. On Windows, this includes the drive letter if present. If path is a relative path and the parent directory is the current working directory, returns ".".
Get the drive portion of a path.
Performs tilde expansion in paths on POSIX systems. On Windows, this function does nothing.
Compares filename characters.
Compares file names and returns
Matches a pattern against a path.
Determines whether a path is absolute or not.
Determines whether the given character is a directory separator.
Determines whether a path starts at a root directory.
Checks that the given file or directory name is valid.
Checks whether path is a valid path.
Slice up a path into its elements.
Translates path into a relative path.
Returns the root directory of the specified path, or null if the path is not rooted.
Sets or replaces an extension.
Strips the drive from a Windows path. On POSIX, the path is returned unaltered.
Remove extension from path.
Set the extension of path to ext if path doesn't have one.
Replace existing extension on filespec with new one.