Please help me to find an elegant way to get file path without extension; cut off file extension from path or something.
2 Answers
Check the Path::file_stem
method. You can find an example there. It works at least from Rust 1.6.
-
9Is there a method which gets the full absolute path before extension, not just the filename?– ditoslavCommented Dec 9, 2020 at 15:07
-
do you know the bahaviour if the file name has two extensions like "file.abc.xyz"? Commented Jul 5, 2023 at 22:03
-
@AndrewMackenzie the linked docs answer this: it returns "the portion of the file name before the final
.
" Commented Oct 20, 2023 at 18:53
Using the Path::with_extension("")
method gives you the full path with a possible file extension removed.
-
1This correctly answers the question, as if the input is a path with intermediate directories, this returns the full path, with the file_stem. Commented Nov 30, 2022 at 11:26