Random stuff, testing things, and so on.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

34 lines
770 B

use std::env;
use std::path::Path;
use std::path::PathBuf;
fn main() {
let args = env::args();
if args.len() != 2 {
println!("Missing executable name");
return;
}
let command = PathBuf::from(&args.last().unwrap());
println!("Searching for {:?}...", command);
if command.exists() {
println!("Command is here!");
return;
}
println!("Exe is in {:?}", find_in_path(&command));
}
fn find_in_path(command: &Path) -> Option<PathBuf> {
env::split_paths(&env::var_os("PATH")?)
.filter_map(|dir| {
let full_path = dir.join(&command);
if full_path.exists() {
Some(full_path)
} else {
None
}
})
.next()
}