Path::file_name
and Path::file_stem
shouldn't treat backslashes as part of the file stem
#52816
Labels
C-feature-request
Category: A feature request, i.e: not implemented / a PR.
O-wasm
Target: WASM (WebAssembly), http://webassembly.org/
O-windows
Operating system: Windows
T-libs-api
Relevant to the library API team, which will review and decide on the PR/issue.
Why do
Path::file_name
andPath::file_stem
treat backslashes as part of the file stem? (On Windows.)The file stem should not include the folders of the path and
\
s, only the final file name's stem.https://play.rust-lang.org/?gist=15996188fbddf77e28dba123495a47ac&version=stable&mode=debug&edition=2015
prints:
should print:
just like it does with forward slashes.
Btw,
for comp in p.components() { println!("{:?}", comp); }
prints onlyNormal("a\\b\\c.ext")
.https://play.rust-lang.org/?gist=b9732062b47e5959b4c4221cd39e421a&version=stable&mode=debug&edition=2015
Btw, is it related to this? #29008
EDIT: I forgot to mention that I'm compiling to wasm32-unknown-unknown.
My yew frontend deals with windows paths coming from my sqlite db (song files).
And in the frontend I need to extract the file_stem from windows paths.
It works correctly if I replace
\
by/
before callingPath::new(&path).file_stem().map_or_else(|| "".into(), |x| x.to_string_lossy().to_string())
, but thats a hack :/What's the recommended way to handle paths in a cross-platform way?
("cross" in the sense of "cross-compiling", but at runtime. Handling Windows paths on wasm32-unknown-unknown with something like std
Path
. Similarly when e.g. generating Windows bat scripts from a Rust executable running on linux, that needs stdPath
to interpret\
as a component separator..)The text was updated successfully, but these errors were encountered: