Class Path
Performs operations on System.String instances that contain file or directory path information.
public static class Path
- Inheritance
-
Path
- Inherited Members
Methods
Combine(params string[])
Gets the combined full path.
public static string Combine(params string[] paths)
Parameters
pathsstring[]Paths to combine.
Returns
- string
Combined absolute path.
Exceptions
- ArgumentNullException
Thrown when
pathsis null.
GetBaseDirectory(string, string)
Gets the base path that ends with a folder name. This function is case invariant (e.g: GetBaseDirectory("D:\Lisrt\Projects\LisRT\SomeFolder", "LISRT") returns "D:\Lisrt\Projects\LisRT").
public static string GetBaseDirectory(string path, string baseFolder)
Parameters
Returns
- string
null when the
pathdoes not contain a folder namedbaseFolder, otherwise the base folder name.
Examples
string basePath = Path.GetBaseDirectory("D:\Lisrt\Projects\LisRT\SomeFolder", "LISRT");
returns "D:\Lisrt\Projects\LisRT"
Exceptions
- ArgumentNullException
Thrown when a parameter is null.
- ArgumentException
Thrown when
baseFoldercontains a directory separator char.
GetRelativPath(string, string)
Gets the path, relative to a base directory if possible.
public static string GetRelativPath(string path, string basePath)
Parameters
pathstringAbsolute path, containing the base directory. This must not be a path to a file.
basePathstringAbsolute base directory.
Returns
- string
The path relative to the
basePathorpathifpathdoesn't containbasePath.
Exceptions
- ArgumentNullException
Thrown when
pathorbasePathis null, empty or whitespace.- ArgumentException
Thrown when
basePathcontains a file extension.
IsSubPathOf(string, string)
Returns true if path starts with the path baseDirPath.
The comparison is case-insensitive, handles / and \ slashes as folder separators and
only matches if the base directory folder name is matched exactly ("c:\foobar\file.txt" is not a sub path of "c:\foo").
public static bool IsSubPathOf(this string path, string baseDirPath)
Parameters
Returns
- bool
True if
pathstarts with the pathbaseDirPath.