diff --git a/src/main.rs b/src/main.rs index a978467..f56c371 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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)); @@ -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::*; @@ -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/"); + } }