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

  • Thread starter Thread starter Darious Snell
  • Start date Start date
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!
 
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
 
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
 
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
 
Back
Top