Returns the directory path of a file.
[Visual Basic] Public Shared Function GetDirectoryNameFromPath( _ ByVal path As String _ ) As String [C#] public static string GetDirectoryNameFromPath( string path ); [C++] public: static String* GetDirectoryNameFromPath( String* path ); [JScript] public static function GetDirectoryNameFromPath( path : String ) : String;
The directory path of the given path, or a null reference (in Visual Basic Nothing) if the given path denotes a root.
Exception Type | Condition |
---|---|
ArgumentException | path contains invalid characters. |
ArgumentException | path is empty or contains only whitespaces. |
This method effectively removes the last element of the given file path, returning a string consisting of all characters up to but not including the last backslash ("\") in the file path. The returned value is null if the file path is null or if the file path denotes a root (such as "\", "C:", or "\\server\share").