In Rust 1.1, std::fs::PathExt
is marked unstable; how do I check the existence of a file or directory?
Is there a canonical solution for this or do i have to read the source of std::fs::PathExt
?
Is there maybe a crate that delivers this functionality?
PathExt
is simple wrappers around std::fs::metadata
; if the path doesn’t exist, metadata
will return an error, so PathExt.exists()
is a simple metadata(self).is_ok()
.
Typically you should be using is_file
or is_dir
instead, though; they correspond to metadata(self).map(|m| m.«is_file or is_dir»()).unwrap_or(false)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With