Reputation: 81342
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
Upvotes: 10
Views: 2241
Reputation: 34421
string s = System.IO.Path.GetFileName(@"C:\MyDir1\MyDir2\MyDir3")
Upvotes: 0
Reputation: 2845
try this
string s =new System.IO.DirectoryInfo(@"C:\MyDir1\MyDir2\MyDir3").Name;
Upvotes: 2