[英]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?我有一个向量,它有一组文件路径,可以获取 mp3 文件列表。我需要做的是删除路径并从每个向量项中获取文件名,所以如果我有
/home/user/Downloads/filename.ext
提取的字符串应该是filename.ext
我如何在 rust 中实现?
You can try this你可以试试这个
let path = Path::new("my_folder/file.txt");
let filename = path.file_name().unwrap();
println!("{}", filename.to_str().unwrap());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.