Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::path::PathBuf;
- use std::env;
- use std::io;
- fn inner_main() -> io::Result<PathBuf> {
- let exe = env::current_exe()?;
- let dir = exe.parent().expect("Executable must be in some directory");
- let dir = dir.join("nvs");
- Ok(dir)
- }
- fn main() {
- // inner_main() returns a Result so you need to either handle the error or
- // do what I'm doing which will either return success or panic.
- let path = inner_main().expect("Couldn't get path");
- // It's somewhat involved to turn a PathBuf into a String (and can fail)
- // but you can do it like this.
- let path_string = path.into_os_string().into_string().unwrap();
- println!("Here is the string path: '{}'", path_string);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement