tags:

views:

69

answers:

2

I just came across what seems like a weird design choice:

System.IO.Path.GetDirectoryName(@"C:\folder\file.ext")

returns "C:\folder"

but

System.IO.Path.GetDirectoryName(@"C:\")

returns null.

I could understand it better if the first example returned "folder".

Any ideas why this is the case? And what do you do when you just want to get the folder path?

A: 

Actually the function would have been better named GetPathName. it returns the full path of the directory of the filename you passed.

RageZ
+3  A: 
Traveling Tech Guy
Well, when people ask about "weird design choice", you should assume they know it's by design... :)
Kobi
@Kobi, thank you for having read my question, 4 upvotes say you are in the minority...
Benjol
Sorry @Benjol, I didn't realize you were asking about the design itself. My guess is that the internal logic of the function is to take a path, go up one level and return that as the answer (i.e. C:\folder\file -> C:\folder). Since there's nowhere to go up from a root directory - you get a null.
Traveling Tech Guy