O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Directory.GetParent Method

Class

System.IO.Directory

Syntax

GetParent(path)
path (required; String)

A valid path to a directory

Return Value

A DirectoryInfo object representing the parent directory of path (assuming that path is valid).

Rules at a Glance

  • path can be either an absolute path (a complete path from the root directory to the directory whose filenames are to be retrieved) or a relative path (starting from the current directory to the directory whose filenames are to be retrieved).

  • path can be either a path on the local system, the path of a mapped network drive, or a UNC path.

  • path cannot contain wildcard characters.

Programming Tips and Gotchas

The DirectoryInfo object has properties Name and ToString (among others). The Name property returns only the name of the directory, while the ToString property returns its absolute path. Thus, the following code displays the string program files:

MsgBox(Directory.GetParent("c:\program files\accessories").Name)

whereas the following code displays the string c:\program files:

MsgBox(Directory.GetParent("c:\program files\accessories").ToString)

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required