fix: improve get_file_name_from_path to use std Path
This commit is contained in:
parent
2001434ab5
commit
c7002aef34
1 changed files with 4 additions and 3 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{BufRead, BufReader},
|
io::{BufRead, BufReader},
|
||||||
|
path::Path,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
|
@ -23,9 +24,9 @@ pub fn read_lines(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_file_name_from_path(file_path: &str) -> String {
|
fn get_file_name_from_path(file_path: &str) -> String {
|
||||||
match file_path.rsplit('/').next() {
|
match Path::new(file_path).file_name() {
|
||||||
Some(name) => name.into(),
|
Some(name) => name.to_string_lossy().to_string(),
|
||||||
None => file_path.into(),
|
None => String::from("unknown"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue