Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Get A Filename From A Rust Path Without The Extension

Use `file_stem()`` to get a filename from a path without its extensio

Code

use std::path::PathBuf;

fn main() {
  let path = PathBuf::from("some/path/to/alfa.html");
  let file_name = path.file_stem().unwrap().to_string_lossy();
  println!("{}", file_name);
}

Results

alfa

References