My.Computer.FileSystem.GetParentPath Method

Returns the parent path of the provided path.

' Usage
Dim value As String = My.Computer.FileSystem.GetParentPath(path)
' Declaration
Public Function GetParentPath( _
   ByVal path As String _
) As String

Parameters

  • path
    String. Path to be examined. Required.

Return Value

String.

Exceptions

The following conditions may cause an exception to be thrown:

  • The path is not valid for one of the following reasons: it is a zero-length string; it contains only white space; it contains invalid characters; or it is a device path (starts with \\.\) (ArgumentException).

  • Path does not have a parent path because it is a root path (ArgumentException).

  • The path is not valid because it is Nothing (ArgumentNullException).

  • The path exceeds the system-defined maximum length (PathTooLongException).

  • A file or directory name in the path contains a colon (:) or is in an invalid format (NotSupportedException).

  • The user lacks necessary permissions to view the path (SecurityException).

Remarks

This is a string operation; the file system is not examined.

Example

This example gets the parent path for C:\Backups\Tmp\Test.

Dim strPath As String
strPath = My.Computer.FileSystem.GetParentPath("C:\backups\tmp\test")
MsgBox(strPath)

Requirements

Namespace:Microsoft.VisualBasic.MyServices

Class:FileSystemProxy (provides access to FileSystem)

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Availability by Project Type

Project type

Available

Windows Application

Yes

Class Library

Yes

Console Application

Yes

Windows Control Library

Yes

Web Control Library

Yes

Windows Service

Yes

Web Site

Yes

Permissions

The following permission may be necessary:

Permission

Description

FileIOPermission

Controls the ability to access files and folders. Associated enumeration: Unrestricted.

For more information, see Code Access Security and Requesting Permissions.

See Also

Tasks

How to: Parse File Paths in Visual Basic

Reference

My.Computer.FileSystem Object

GetParentPath

Other Resources

File, Directory, and Drive Properties in Visual Basic