dotnet / dotnet/runtime

Documentation: Handling of problematic paths on Windows

Open
#120,995 2 comments 1 reaction 0 assignees View on GitHub
area-System.IO documentation
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

Context: https://github.com/dotnet/runtime/pull/120639#discussion_r2453528148

The documentation for handling of problematic paths on Windows, such as paths that with trailing spaces, needs improvements.

- There is https://learn.microsoft.com/en-us/dotnet/framework/migration-guide/mitigation-path-normalization however it talks about .NET Framework and it is not clear which parts of it apply to .NET Core

- The documentation for various System.IO APIs include snippets that are either applicable to Windows only or .NET Framework only. For example, https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.createdirectory says "Trailing spaces are removed from the end of the path parameter before creating the directory." that is applicable to Windows only.

- The documentation should include best practices for writing code that handles these paths correctly.
- `FileInfo` and `DirectoryInfo` do support the trailing spaces, `File` and `Directory` do not.
- Handles these paths correctly: `foreach (var ff in new DirectoryInfo(".").EnumerateFiles()) { using (var fs = fi..Open(FileMode.Open)) { ... } }`
- This is going to fail on these paths: `foreach (var f in Directory.EnumerateFiles(".")) { using (var fs = File.Open(f, FileMode.Open)) { ... } }`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.