home
NOTE: Under Construction - I'm in the middle of upgrading my site and lots of stuff is kinda broken. Please forgive the mess.

Get A Filename From A Path In Rust

April 2023
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.

═══ § ═══