Gets a value indicating whether the specified path string contains absolute or relative path information.
[Visual Basic]
Public Shared Function IsPathRooted( _
ByVal path As String _
) As Boolean
[C#]
public static bool IsPathRooted(
string path
);
[C++]
public: static bool IsPathRooted(
String* path
);
[JScript]
public static function IsPathRooted(
path : String
) : Boolean;
Parameters
- path
- The path to test.
Return Value
true if path contains an absolute path; otherwise, false.
Exceptions
Remarks
This method does not verify that the path or file name exists.
IsPathRooted returns true for path strings such as "\\MyDir\\MyFile.txt" and "C:\\MyDir". It returns false for path strings such as "MyDir".
For an example of using this method, see the Example section below. The following table lists examples of other typical or related I/O tasks.
Example
[Visual Basic, C#, C++] The following example demonstrates a use of the IsPathRooted property.
[Visual Basic]
Dim fileName As String = "C:\mydir\myfile.ext"
Dim UncPath As String = "\\myPc\mydir\myfile"
Dim relativePath As String = "mydir\sudir\"
Dim result As Boolean
result = Path.IsPathRooted(fileName)
Console.WriteLine("IsPathRooted('{0}') returns {1}", fileName, result)
result = Path.IsPathRooted(UncPath)
Console.WriteLine("IsPathRooted('{0}') returns {1}", UncPath, result)
result = Path.IsPathRooted(relativePath)
Console.WriteLine("IsPathRooted('{0}') returns {1}", relativePath, result)
[C#]
string fileName = @"C:\mydir\myfile.ext";
string UncPath = @"\\myPc\mydir\myfile";
string relativePath = @"mydir\sudir\";
bool result;
result = Path.IsPathRooted(fileName);
Console.WriteLine("IsPathRooted('{0}') returns {1}",
fileName, result);
result = Path.IsPathRooted(UncPath);
Console.WriteLine("IsPathRooted('{0}') returns {1}",
UncPath, result);
result = Path.IsPathRooted(relativePath);
Console.WriteLine("IsPathRooted('{0}') returns {1}",
relativePath, result);
[C++]
String * fileName = S"C:\\mydir\\myfile.ext";
String * UncPath = S"\\\\myPc\\mydir\\myfile";
String * relativePath = S"mydir\\sudir\\";
bool result;
result = Path::IsPathRooted(fileName);
Console::WriteLine(S"IsPathRooted('{0}') returns {1}",
fileName, result.ToString());
result = Path::IsPathRooted(UncPath);
Console::WriteLine(S"IsPathRooted('{0}') returns {1}",
UncPath, result.ToString());
result = Path::IsPathRooted(relativePath);
Console::WriteLine(S"IsPathRooted('{0}') returns {1}",
relativePath, result.ToString());
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard
See Also
Path Class | Path Members | System.IO Namespace | Working with I/O | Reading Text from a File | Writing Text to a File