Almost embarrarased to ask this string manipulation question....

D

Darious Snell

I am looking for an elegant way to return just the directory part of a string that
represents a fully qualified path to a file.

Example:
MyString = c:\MyDir\Mydir2\Mydir3\Myfile1.txt
I want to return just c:\MyDir\Mydir2\Mydir3

Thanks!
 
J

johnb41

I always ask questions around here, but now I can actually help out! :)

Imports system.io

dim path as string = "c:\MyDir\Mydir2\Mydir3\Myfile1­.txt"
dim result as string
result = path.getdirectoryname(path)

Haven't tested it, but i think this should work. No text parsing
necessary! :)

John
 
D

Darious Snell

system.io.path.getdirectoryname(path) worked like a charm.
Cheers!


I always ask questions around here, but now I can actually help out! :)

Imports system.io

dim path as string = "c:\MyDir\Mydir2\Mydir3\Myfile1­.txt"
dim result as string
result = path.getdirectoryname(path)

Haven't tested it, but i think this should work. No text parsing
necessary! :)

John
 
J

james

Hey! I'm glad you posted that! I have been using a really convoluted bit of code to get the same results to add file name only
to a listbox. Went from several lines of code to TWO!!
Thanks for sharing.
james
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top