get the directory name of the directory containing the directory

How to get the folder name from the full path to the folder?

This is the path to the file,

"c:\projects\roott\wsdlproj\devlop\beta2\text"

Here the text is the name of the folder.

But I want to get a folder containing text , i.e. beta2

+5
source share
2 answers

Path.GetDirectoryNamemethod can be used to return "c: \ projects \ roott \ wsdlproj \ devlop \ beta2" , as shown below:

Dim filePath As String = "c:\projects\roott\wsdlproj\devlop\beta2\text"
Dim directory As String = Path.GetDirectoryName(filePath)

To get only the name of the parent folder "beta2" , you can split the entry and take the second last entry, given that the input is really accurate:

Dim split As String() = filePath.Split("\")
Dim parentFolder As String = split(split.Length - 2)
+9

7/09/2012 10:42 io.path.getFileName(filePath)

+9

All Articles