Skip to content

Path.GetFileName behavior change on .NET Core #2644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
JeremyKuhne opened this issue Jun 26, 2019 · 1 comment
Open

Path.GetFileName behavior change on .NET Core #2644

JeremyKuhne opened this issue Jun 26, 2019 · 1 comment
Labels
area-System.IO Pri1 Indicates issues/PRs that are high priority Pri3 Indicates issues/PRs that are low priority
Milestone

Comments

@JeremyKuhne
Copy link
Member

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.

@dotnet-bot dotnet-bot added the untriaged New issue has not been triaged by the area owner label Jun 26, 2019
@JeremyKuhne
Copy link
Member Author

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.

@rpetrusha rpetrusha self-assigned this Jun 27, 2019
@rpetrusha rpetrusha added 📁 Repo - dotnet-api-docs and removed untriaged New issue has not been triaged by the area owner labels Jun 27, 2019
@rpetrusha rpetrusha added this to the July 2019 milestone Jun 27, 2019
@rpetrusha rpetrusha modified the milestones: July 2019, August 2019 Jul 26, 2019
@rpetrusha rpetrusha modified the milestones: August 2019, September 2019 Sep 9, 2019
@rpetrusha rpetrusha modified the milestones: September 2019, Backlog Oct 11, 2019
@rpetrusha rpetrusha added the Pri1 Indicates issues/PRs that are high priority label Oct 11, 2019
@rpetrusha rpetrusha removed their assignment Oct 11, 2019
@PRMerger13 PRMerger13 added the Pri3 Indicates issues/PRs that are low priority label Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.IO Pri1 Indicates issues/PRs that are high priority Pri3 Indicates issues/PRs that are low priority
Projects
None yet
Development

No branches or pull requests

5 participants