Re:Why Does Windows Use Backslash as Path Separator?
by agumonkey on Wednesday April 24, 2024 @06:12PM
(#40150464)
I remember one article about someone porting code from *nix to windows and having almost no issue due to the author leveraging pathlib. Just a side note.
Re:Why Does Windows Use Backslash as Path Separator?
by Const-me on Wednesday April 24, 2024 @10:55PM
(#40152841)
Same applies to C#. The standard library has pretty good APIs for dealing with file names and paths.
In my experience, a program written in modern .NET 5+ and tested on Windows has a high probability to run flawlessly on Linux, without even a recompilation.
- a path is not a unique identifier of a file system object. They don’t have canonical names.
- don’t make any assumptions about case sensitivity, what file names are valid, or what the longest possible path is.
- avoid baking paths from strings as as much as possible. Use constructs like PathBuf (Rust) that prevent footguns like duplicated or incorrect dir separators. Never use a literal path separator char ‘/‘ or ‘\’ in code is a good rule of thumb.