简体   繁体   中英

How to remove path and get the filename in rust?

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?

You can try this

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM