Please help me to find an elegant way to get file path without extension; cut off file extension from path or something.
How to get file path without extension in Rust?
Asked Answered
Check the Path::file_stem
method. You can find an example there. It works at least from Rust 1.6.
Is there a method which gets the full absolute path before extension, not just the filename? –
Crowell
do you know the bahaviour if the file name has two extensions like "file.abc.xyz"? –
Musketeer
@AndrewMackenzie the linked docs answer this: it returns "the portion of the file name before the final
.
" –
Phineas Using the Path::with_extension("")
method gives you the full path with a possible file extension removed.
This correctly answers the question, as if the input is a path with intermediate directories, this returns the full path, with the file_stem. –
Musketeer
© 2022 - 2024 — McMap. All rights reserved.