Path: IsPathRooted

IsPathRooted

Gets a value indicating whether the specified path string contains a root.



 Public Function IsPathRooted(
	  ByRef Path As String ) As Boolean

Parameters

Path
[ByRef] String. The path to test.

Return Values

Boolean -  True if Path contains a root; otherwise False.

Remarks

The IsPathRooted method returns True if the first character is a directory separator character such as "\", or if the path starts with a drive letter and colon (:). For example, it returns True for Path strings such as "\\MyDir\\MyFile.txt", "C:\\MyDir", or "C:MyDir". It returns False for Path strings such as "MyDir".

The method does not verify that the path or file name exists.

Exceptions

ExceptionCondition
ArgumentException Path contains one or more of the invalid characters defined in GetInvalidPathChars.

Examples

The following code example demonstrates how the IsPathRooted method can be used to test three strings.

Public Sub Main()
    Const FileName As String = "C:\MyDir\MyFile.Ext"
    Const UncPath As String = "\\MyPC\MyDir\MyFile"
    Const RelativePath As String = "MyDir\SubDir\"
    
    Dim Result As Boolean
    
    Result = Path.IsPathRooted(FileName)
    Debug.Print CorString.Format("IsPathRooted('{0}') returns {1}", FileName, Result)
    
    Result = Path.IsPathRooted(UncPath)
    Debug.Print CorString.Format("IsPathRooted('{0}') returns {1}", UncPath, Result)
    
    Result = Path.IsPathRooted(RelativePath)
    Debug.Print CorString.Format("IsPathRooted('{0}') returns {1}", RelativePath, Result)
End Sub

' This example code produces the following output.
'
'    IsPathRooted('C:\MyDir\MyFile.Ext') returns True
'    IsPathRooted('\\MyPC\MyDir\MyFile') returns True
'    IsPathRooted('MyDir\SubDir\') returns False

See Also

Project CorLib Overview

Class Path Overview

GetInvalidPathChars