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
paths
string[]Paths to combine.
Returns
- string
Combined absolute path.
Exceptions
- ArgumentNullException
Thrown when
paths
is 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
path
does 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
baseFolder
contains 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
path
stringAbsolute path, containing the base directory. This must not be a path to a file.
basePath
stringAbsolute base directory.
Returns
- string
The path relative to the
basePath
orpath
ifpath
doesn't containbasePath
.
Exceptions
- ArgumentNullException
Thrown when
path
orbasePath
is null, empty or whitespace.- ArgumentException
Thrown when
basePath
contains 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
path
starts with the pathbaseDirPath
.