tags:

views:

35

answers:

3

Given the following directory:

string fullpath = "C:\MyDir1\MyDir2\MyDir3";

I would like to return "MyDir3" - this being the directory name (not full path, of a directory) , I know I can do this using string manipulation, but is there an easy (built in way) to achieve this using framework classes?

Thanks

+7  A: 
string dir = new DirectoryInfo(fullpath).Name;
Thomas Levesque
Seems good, thanks - and lol at first answer :)
JL
A: 

try this

string s =new  System.IO.DirectoryInfo(@"C:\MyDir1\MyDir2\MyDir3").Name;
hallie
A: 
string s = System.IO.Path.GetFileName(@"C:\MyDir1\MyDir2\MyDir3")
erikkallen