If i have:
C:\\temp\\foo\\bar\\
(NOTE: bar is a directory)
how can i parse out:
bar
Just use:
string dirname = new DirectoryInfo(@"C:\temp\foo\bar\").Name;
According to MSDN this returns the name of the directory, not the full path.
Link to MSDN Library
Hope this helps.........
I can think of 4 ways instantly
Try this
string DirName = System.IO.Directory.GetParent(@"C:\temp\foo\bar\").Name;
It looks like a bunch of people have withdrawn their answers, which is possibly a shame.
This one's got to be worth stating, only for the "teach a man to fish" quality of it - it's short, elegant and made of two separate things that, once learned, can be re-applied to other problems.
string lastPiece = wholePath.Split('\\').Last();
Last
will throw if the list is empty.