How to get the folder name from the full path of folder?
This is file path,
"c:\projects\roott\wsdlproj\devlop\beta2\text"
Here text is the folder name.
But i want to get the folder containing text, that is beta2
In order to obtain the Current Working Directory in Python, use the os. getcwd() method. This function of the Python OS module returns the string containing the absolute path to the current working directory.
A path is a string that provides the location of a file or directory. A path does not necessarily point to a location on disk; for example, a path might map to a location in memory or on a device. The exact format of a path is determined by the current platform.
To find out which directory in python you are currently in, use the getcwd() method. Cwd is for current working directory in python. This returns the path of the current python directory as a string in Python. To get it as a bytes object, we use the method getcwdb().
The Path.GetDirectoryName
method 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 just the name of the parent folder, "beta2", you can split the input and take the second last entry, given that the input is indeed accurate:
Dim split As String() = filePath.Split("\")
Dim parentFolder As String = split(split.Length - 2)
Fri 7/09/2012 10:42 AM io.path.getFileName(filePath) will return the folder name
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With