Created
August 21, 2020 10:56
-
-
Save flxxyz/05a1df87a05601be23a561e5d9b1d205 to your computer and use it in GitHub Desktop.
rust 不同系统转换目录路径
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn convert_path(path_str: &str) -> String { | |
if cfg!(target_os = "windows") { | |
String::from(path_str.replace("\\", "/")) | |
} else { | |
String::from(path_str) | |
} | |
} | |
fn main() { | |
println!("hello world!"); | |
let test_path = String::from("C:\\windows\\system32\\cmd.exe"); | |
println!(convert_path(test_path)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment