Reputation: 305
I am having a test case in .Net Core 2 where I am providing below input to Path.GetDirectoryName
.
@"C:" + Path.DirectorySeparatorChar
When I assert for Path.GetDirectoryName
in my test case, it returns null
for Windows OS but returns C:
for Linux OS, why so?
Can anyone please explain what wrong I am doing here?
Upvotes: 0
Views: 1440
Reputation: 13736
On Windows, C:\
is a root directory. It doesn't have a name.
On Linux, C:\
is also a directory. It's name is c:
and - since you used a relative path - it's a sub-directory of the current directory.
The problem is that you have correctly used Path.DirectorySeparatorChar
so that the provided path works in both operating systems, but you have used a drive designator (C:), which is something that doesn't exist in Linux.
Upvotes: 1