dotnet-api-docs icon indicating copy to clipboard operation
dotnet-api-docs copied to clipboard

Path.GetFileName behavior change on .NET Core

Open JeremyKuhne opened this issue 6 years ago • 1 comments

In .NET Core we consider Path.GetPathRoot() when finding the filename. The concept of Path.VolumeSeparatorChar is only relevant on Windows 9x machines. So:

.NET Framework

The characters after the last directory separator character in path. If the last character of path is a directory or volume separator character, this method returns Empty.

.NET Core

The characters after the last directory separator character after the path root (see Path.GetPathRoot) in path. If the path only contains a root, returns empty.

We should add to Path.VolumeSeparatorChar that we recommend not using it directly as it is a Win9x anachronism. Use Path.GetPathRoot to determine path roots.

JeremyKuhne avatar Jun 26 '19 17:06 JeremyKuhne

This comment is also misleading:

Because \ is a legal file name on Unix, GetFileName running under Unix-based platforms cannot correctly return the file name from a Windows-based path like C:\mydir\myfile.ext, but GetFileName running under Windows-based platforms can correctly return the file name from a Unix-based path like /tmp/myfile.ext, so the behavior of the GetFileName method is not strictly the same on Unix-based and Windows-based platforms.

It will always return the correct filename based on the semantics of the current operating system. C:\ has no special meaning for Unix, but does for Windows. UNCs and DOS device paths are also Windows specific.

JeremyKuhne avatar Jun 26 '19 17:06 JeremyKuhne