Kuzon
Kuzon

Reputation: 822

How to find the root of a file

I am trying to find the folder that my file is in so I can use it else where. I am using an openfiledialog. So, if the path of the file is "C:\test\test.text". I want to be able to get "c:\test" without the file how would i do this?

Upvotes: 1

Views: 75

Answers (2)

Tim
Tim

Reputation: 28530

If you have the whole path, you can use Path.GetDirectoryName:

Dim filePath As String = Path.GetDirectoryName("C:\test")

That would return C:

Upvotes: 1

Henk Holterman
Henk Holterman

Reputation: 273244

 Dim path as String = System.IO.Path.GetDirectoryName(fileName)

Upvotes: 6

Related Questions