Path: GetFullPath

GetFullPath

Returns the absolute path for the specified path string.



 Public Function GetFullPath(
	  ByRef Path As String ) As String

Parameters

Path
[ByRef] String. The file or directory for which to obtain absolute path information.

Return Values

String -  The fully qualified location of path, such as "C:\MyFile.txt".

Remarks

The absolute path includes all information required to locate a file or directory on a system.

The file or directory specified by Path is not required to exist. For example, if c:\temp\newdir is the current directory, calling GetFullPath on a file name such as test.txt returns c:\temp\newdir\test.txt. The file need not exist.

However, if Path does exist, the caller must have permission to obtain path information for path. Note that unlike most members of the Path class, this method accesses the file system.

This method uses current directory and current volume information to fully qualify Path. If you specify a file name only in Path, GetFullPath returns the fully qualified path of the current directory.

If you pass in a short file name, it is expanded to a long file name.

If a path contains no significant characters it is invalid unless it contains one or more "." characters followed by any number of spaces, then it will be parsed as either "." or "..".

Exceptions

ExceptionCondition
ArgumentException Path is a zero-length string, contains only white space, or contains one or more of the invalid characters defined in GetInvalidPathChars.
-or-
The system could not retrieve the absolute path.
NotSupportedException Path contains a colon (":") that is not part of a volume identifier (for example, "c:\").

Examples

The following code example demonstrates the GetFullPath method.

Public Sub Main()
    Const FileName As String = "MyFile.Ext"
    Const Path1 As String = "MyDir"
    Const Path2 As String = "\MyDir"
    
    Dim FullPath As String
    
    FullPath = Path.GetFullPath(Path1)
    Debug.Print CorString.Format("GetFullPath('{0}') returns '{1}'", Path1, FullPath)
    
    FullPath = Path.GetFullPath(FileName)
    Debug.Print CorString.Format("GetFullPath('{0}') returns '{1}'", FileName, FullPath)
    
    FullPath = Path.GetFullPath(Path2)
    Debug.Print CorString.Format("GetFullPath('{0}') returns '{1}'", Path2, FullPath)
End Sub

' Output is based on your current directory, except
' in the last case, where it is based on the root drive.
'
'    GetFullPath('MyDir') returns 'C:\Program Files (x86)\Microsoft Visual Studio\VB98\MyDir'
'    GetFullPath('MyFile.Ext') returns 'C:\Program Files (x86)\Microsoft Visual Studio\VB98\MyFile.Ext'
'    GetFullPath('\MyDir') returns 'C:\MyDir'

See Also

Project CorLib Overview

Class Path Overview