Home > Back-end >  How to remove path and get the filename in rust?
How to remove path and get the filename in rust?

Time:09-28

I have a Vector that has set of file paths that gets list of mp3 files.what i need to do is remove the path and get the filename from the each of the vector item so if i have /home/user/Downloads/filename.ext the extracted string should be filename.ext how can i implement in rust?

CodePudding user response:

You can try this

let path = Path::new("my_folder/file.txt");
let filename = path.file_name().unwrap();

println!("{}", filename.to_str().unwrap());
  • Related