Path: GetPathRoot |
Returns the root directory information of the specified path.
Public Function GetPathRoot( ByRef Path As String ) As String
This method does not verify that the path or file name exists.
Possible patterns for the string returned by this method are as follows:
Exception | Condition |
---|---|
ArgumentException | Path contains one or more of the invalid characters defined in GetInvalidPathChars. -or- Path is an empty string. |
The following code example demonstrates a use of the GetPathRoot method.
Public Sub Main() Const FileName As String = "MyFile.Ext" Const PathName As String = "\MyDir\" Const FullPath As String = "C:\MyDir\MyFile.Ext" Dim PathNameRoot As String PathNameRoot = Path.GetPathRoot(PathName) Debug.Print CorString.Format("GetPathRoot('{0}') returns '{1}'", PathName, PathNameRoot) PathNameRoot = Path.GetPathRoot(FileName) Debug.Print CorString.Format("GetPathRoot('{0}') returns '{1}'", FileName, PathNameRoot) PathNameRoot = Path.GetPathRoot(FullPath) Debug.Print CorString.Format("GetPathRoot('{0}') returns '{1}'", FullPath, PathNameRoot) End Sub ' This example code produces output similar to the following: ' ' GetPathRoot('\MyDir\') returns '\' ' GetPathRoot('MyFile.Ext') returns '' ' GetPathRoot('C:\MyDir\MyFile.Ext') returns 'C:\'