#executable #path #search #lib #unix #folders #windows

searchpath

A small unix and windows lib to search for executables in PATH folders

4 releases

0.1.3 Nov 7, 2021
0.1.2 Nov 7, 2021
0.1.1 Nov 7, 2021
0.1.0 Nov 7, 2021

#1489 in Filesystem

Download history 17/week @ 2024-02-26 3/week @ 2024-03-04 10/week @ 2024-03-11 20/week @ 2024-04-01 32/week @ 2024-04-15

52 downloads per month

MIT license

5KB
53 lines

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);
    }
}

Dependencies

~42KB