The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Get A Filename From A Path In Rust

TODO: Pull subtitle into page object
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.

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Get A Filename From A Path In Rust


-- code
-- rust

use std::path::PathBuf;

fn main() {

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

}

-- p

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



-- blurb

-- categories
-- Rust 

-- metadata
-- date: 2023-04-05 20:01:32
-- id: 2o1schh3
-- site: aws
-- type: post
-- status: published