rsv_lib/utils/
filename.rs

1use std::path::{Path, PathBuf};
2
3const BAD_FILENAME_CHARACTERS: [char; 9] = ['<', '>', ':', '\\', '/', '\\', '"', '?', '*'];
4
5pub fn new_path(path: &Path, suffix: &str) -> PathBuf {
6    let p = path.with_file_name(format!(
7        "{}{}",
8        path.file_stem().unwrap().to_str().unwrap(),
9        suffix
10    ));
11
12    // new file
13    match path.extension() {
14        Some(e) => p.with_extension(e),
15        None => p,
16    }
17}
18
19pub fn new_file(name: &str) -> PathBuf {
20    let mut path = std::env::current_dir().unwrap();
21    path.push(name);
22
23    path
24}
25
26pub fn str_to_filename(s: &str) -> String {
27    s.replace(BAD_FILENAME_CHARACTERS, "")
28}
29
30pub fn dir_file(dir: &Path, name: &str) -> PathBuf {
31    let mut out = dir.to_path_buf();
32    out.push(name);
33
34    out
35}
36
37pub fn full_path(f: &str) -> PathBuf {
38    // current file
39    let mut path = std::env::current_dir().unwrap();
40    path.push(Path::new(f));
41
42    path
43}