Share via


Path.GetDirectoryName Method

Returns the directory information for the specified path string.

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

Syntax

public static string GetDirectoryName (
         stringpath
)

Parameters

  • path
    The path of a file or directory.

Return Value

A String containing directory information for path, or a null reference if path denotes a root directory, is the empty string (""), or is a null reference. Returns String.Empty if path does not contain directory information.

Remarks

In most cases, the string returned by this method consists of all characters in the path up to but not including the last DirectorySeparatorChar or AltDirectorySeparatorChar. 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 or AltDirectorySeparatorChar, 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".

Version Information

Available in the .NET Micro Framework versions 3.0, 4.0, and 4.1.

See Also

Reference

Path Class
Path Members
System.IO Namespace