rust 获取当前exe所在路径

180it 2023-03-06 AM 862℃ 0条

use std::fs::create_dir_all;
use std::path::Path;
use std::{env, fs};

fn main() {

let p = env::current_dir();
println!("当前主目录:{:?}", p.expect("REASON").display());
println!("当前主目录:{:?}", std::env::current_dir().unwrap());
println!("当前EXE路径包含exe:{:?}", std::env::current_exe().unwrap());

let exe = std::env::current_exe().unwrap();
let dir = exe.parent().expect("Executable must be in some directory");
println!("当前EXE路径:{:?}", dir);

}

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

rust 获取当前exe所在路径