The following methods lets you manipulate and work with file and directory paths:
- Combine - combines one or more paths into one. This is most commonly used to combine an absolute base path with a relative other path, for example combining "D:\Movies" with "Terminator.avi" will result in the path "D:\Movies\Terminator.avi".
- Normalize - normalizes a given path by resolving all "." and ".." path segments. For example, normalizing "C:\Documents\..\MyFile.txt" will result in "C:\MyFile.txt".
- IsPathRooted - checks whether the specified path string contains a root, for example "C:\Documents\MyFile.txt" contains a root - "C:\".
- GetPathRoot - gets the root directory information of the specified path (e.g. "C:\").
- MakeRelativePath - gets a relative path leading from the first path (fromPath) to the second one (toPath). For example, if you pass "C:\Documents\Mark" as fromPath and "C:\Documents\Jane" as toPath, the resulting relative path will be "..\Jane".
The following methods of the NPath static class are related to file paths:
- GetExtension - gets the extension of the specified file name without the dot, for example: "txt", "rtf", "docx", etc. If the given file name does not have an extension, String.Empty is returned.
- GetFileName - gets only the file name and the extension of the given path. For example, if the path is "C:\Documents\MyFile.txt", this method returns "MyFile.txt".
- GetFileNameWithoutExtension - gets only the file name of the given full file path without the file extension. For example, if the path is "C:\Documents\MyFile.txt", this method returns "MyFile".
- GetFullPath - returns the absolute path for the specified path string using the current directory if the given path string is relative.
The following methods the NPath class are related to directory paths:
- GetFullFolderName - gets the full folder name of the given path. For example, if the path is "C:\Documents\MyFile.txt", this method returns "C:\Documents".
- GetParentFolderName - gets the name of the parent folder of the given path. For example, if the path is "C:\Documents\MyFile.txt", this method returns "Documents".