7 releases (stable)

1.0.4 Oct 4, 2024
1.0.3 Sep 10, 2024
1.0.1 Feb 8, 2021
1.0.0 Jan 11, 2021
0.1.0 Sep 20, 2017

#57 in Filesystem

Download history 70376/week @ 2024-07-15 75699/week @ 2024-07-22 74908/week @ 2024-07-29 76199/week @ 2024-08-05 87623/week @ 2024-08-12 70693/week @ 2024-08-19 86032/week @ 2024-08-26 92693/week @ 2024-09-02 87648/week @ 2024-09-09 85232/week @ 2024-09-16 91875/week @ 2024-09-23 94263/week @ 2024-09-30 94384/week @ 2024-10-07 96709/week @ 2024-10-14 103113/week @ 2024-10-21 86091/week @ 2024-10-28

386,085 downloads per month
Used in 175 crates (74 directly)

Apache-2.0/MIT

9KB
94 lines

is_executable

Is there an executable file at the given path?

CI

A small helper function which determines whether or not the given path points to an executable file. If there is no file at the given path, or the file is not executable, then false is returned. When there is a file and the file is executable, then true is returned.

This crate works on both Unix-based operating systems (macOS, Linux, FreeBSD, etc...) and Windows.

Does not help with time-of-check to time-of use (TOCTOU) races.

The API comes in two flavors:

  1. An extension trait to add an is_executable method on std::path::Path:

    use std::path::Path;
    use is_executable::IsExecutable;
    
    fn main() {
        let path = Path::new("some/path/to/a/file");
    
        // Determine if `path` is executable.
        if path.is_executable() {
            println!("The path is executable!");
        } else {
            println!("The path is _not_ executable!");
        }
    }
    
  2. For convenience, a standalone is_executable function, which takes any AsRef<Path>:

    use std::path::Path;
    
    use is_executable::is_executable;
    
    fn main() {
        let path = Path::new("some/path/to/a/file");
    
        // Determine if `path` is executable.
        if is_executable(&path) {
            println!("The path is executable!");
        } else {
            println!("The path is _not_ executable!");
        }
    }
    

License: Apache-2.0/MIT

Dependencies

~175KB