Crate is_executable [−] [src]
Is there an executable file at the given path?
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 returend.
Answering this question is OS specific: some operating systems (Windows) do not
distinguish between executable and non-executable file permissions. On such
OSes, if there is a file at the given path, then true is returned.
The API comes in two flavors:
An extension trait to add an
is_executablemethod onstd::path::Pathandstd::fs::Permissions:use is_executable::IsExecutable; use std::fs; use std::path::Path; 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!"); } // Determine if some `std::fs::Metadata`'s `std::fs::Permissions` are // executable. if fs::metadata("some/path")?.permissions().is_executable() { println!("The permissions are executable!"); } else { println!("The permissions are _not_ executable!"); }
For convenience, a standalone
is_executablefunction, which takes anyAsRef<Path>:use is_executable::is_executable; use std::path::Path; let path = Path::new("some/path/to/a/file"); if is_executable(&path) { println!("The path is executable!"); } else { println!("The path is _not_ executable!"); }
Traits
| IsExecutable |
An extension trait for |
Functions
| is_executable |
Returns |