GetDirectoryName Method

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Returns the directory information for the specified path string.

Namespace:  System.IO
Assembly:  System.IO (in System.IO.dll)

static String^ GetDirectoryName(
	String^ path


Type: System..::..String
The path of a file or directory.

Return Value

Type: System..::..String
Directory information for path, or nullNothingnullptrunita null reference (Nothing in Visual Basic) if path denotes a root directory or is null. Returns String..::..Empty if path does not contain directory information.

In most cases, the string returned by this method consists of all characters in the path up to but not including the last DirectorySeparatorChar. If the path consists of a root directory, such as "c:\", null is returned. Note that this method does not support paths using "file:". Because the returned path does not include the DirectorySeparatorChar, passing the returned path back into the GetDirectoryName method will result in the truncation of one folder level per subsequent call on the result string. For example, passing the path "C:\Directory\SubDirectory\test.txt" into the GetDirectoryName method will return "C:\Directory\SubDirectory". Passing that string, "C:\Directory\SubDirectory", into GetDirectoryName will result in "C:\Directory".