Skip to content

Commit

Permalink
Fix issues with backslash-paths on Windows πŸ³οΈβ€πŸŒˆπŸž
Browse files Browse the repository at this point in the history
fixes #10
  • Loading branch information
tgotwig committed Jul 29, 2020
1 parent a1e76dd commit f32647c
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ fn main() -> std::io::Result<()> {
let file_format = matches.value_of("format").unwrap();

// i/o paths
let input_dir = Path::new(matches.value_of("DIR").unwrap());
let input_dir = format_path(matches.value_of("DIR").unwrap());
let input_dir = Path::new(&input_dir);
let output_list = input_dir.join("input.txt");
let output_vid = input_dir.join(format!("output.{}", file_format));

Expand Down Expand Up @@ -122,6 +123,22 @@ fn is_ffmpeg_available() -> bool {
}
}

fn format_path(path_to_vids: &str) -> String {
let path_to_vids: String = if path_to_vids.starts_with('\\') {
path_to_vids.replacen("\\", "", 1)
} else {
path_to_vids.into()
};

let path_to_vids: String = if !path_to_vids.ends_with('/') && !path_to_vids.ends_with('\\') {
format!("{}/", path_to_vids)
} else {
path_to_vids
};

path_to_vids.replace("\\", "/")
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -130,4 +147,22 @@ mod tests {
fn test_is_ffmpeg_available() {
assert_eq!(is_ffmpeg_available(), true);
}

#[test]
fn test_format_path() {
assert_eq!(
format_path(&String::from("c:\\path\\to\\vids")),
"c:/path/to/vids/"
);
assert_eq!(
format_path(&String::from("\\path\\to\\vids")),
"path/to/vids/"
);
assert_eq!(
format_path(&String::from("\\path\\to\\vids\\")),
"path/to/vids/"
);
assert_eq!(format_path(&String::from("path/to/vids")), "path/to/vids/");
assert_eq!(format_path(&String::from("path/to/vids/")), "path/to/vids/");
}
}

0 comments on commit f32647c

Please sign in to comment.