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 Path In Rust

Code

use std::path::PathBuf;

fn main() {

  let path = PathBuf::from("/Users/alan/Desktop/here.txt");
  println!("{}", path.file_name().unwrap().to_str().unwrap());

}

This goes through `OsStr`` which is why there are two unwraps.