Crates.io | searchpath |
lib.rs | searchpath |
version | 0.1.3 |
source | src |
created_at | 2021-11-07 18:32:02.055778 |
updated_at | 2021-11-07 23:11:19.424336 |
description | A small unix and windows lib to search for executables in PATH folders |
homepage | |
repository | https://github.com/robiot/searchpath |
max_upload_size | |
id | 478183 |
size | 5,118 |
A small unix and windows lib to search for executables in path folders.
Example:
use searchpath::search_path;
use std::ffi::OsString;
fn main() {
let path = std::env::var_os("PATH");
let files = search_path("ba", path.as_ref().map(OsString::as_os_str), None);
for file in files {
println!("{}", file);
}
}
Will print something like
bat
bashbug
bash
base32
basenc
basename
base64
Windows example:
use searchpath::search_path;
use std::ffi::OsString;
fn main() {
let path = std::env::var_os("path");
let path_ext = std::env::var_os("pathext");
let files = search_path("explo", path.as_ref().map(OsString::as_os_str), path_ext.as_ref().map(OsString::as_os_str));
for file in files {
println!("{}", file);
}
}