Mono Class Library: System.IO.Path Overview | MembersSystem.IO.Path.GetPathRoot Method |
Returns the path root component of the specified path. [Edit]
|
A string containing the root directory of path, or null if path is null . Returns string.Empty if the specified path does not contain root information.
Platforms that do not support this feature return path unmodified.
[Edit]
Type Reason ArgumentException path contains one or more implementation-specific invalid characters or is equal to string.Empty . [Edit]
This method does not verify that the path exists.
The exact behavior of this method is implementation-specific.
[Edit]
The following example demonstrates the Path.GetPathRoot(string) method.
C# Example using System; using System.IO; class GetPathRootTest { public static void Main() { string [] paths = { @"\ecmatest\examples\pathtests.txt", "pathtests.xyzzy", @"\", @"C:\", @"\\myserver\myshare\foo\bar\baz.txt" }; foreach (string pathString in paths) { string s = Path.GetPathRoot(pathString); Console.WriteLine("Path: {0} Path root is {1}",pathString, s== null? "null": s); } } }The output is
Path: \ecmatest\examples\pathtests.txt Path root is \
Path: pathtests.xyzzy Path root is
Path: \ Path root is \
Path: C:\ Path root is C:\
Path: \\myserver\myshare\foo\bar\baz.txt Path root is \\myserver\myshare
Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0