-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Description
Context: #120639 (comment)
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.
FileInfoandDirectoryInfodo support the trailing spaces,FileandDirectorydo 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)) { ... } }
- Handles these paths correctly: