std-type
DirEntry: directory entry metadata
A directory iterator yields individual entries. Names are native OS strings. file_type does not follow symbolic links; it is not an authorization check. Use a fresh disposable working directory exclusively controlled by this program. Expected stdout (not executed): note.txt true Common mistake: Assuming every directory entry is a regular file.
Formal Syntax & Structure
rust syntaxrust
entry.path(); entry.file_name(); entry.file_type() -> io::Result<FileType>Working Example
Example Snippetrust
fn main() { use std::fs::{self, File}; use std::io::{Read, Write}; fs::create_dir("bm-fixture").expect("fresh working directory required"); let p = std::path::Path::new("bm-fixture").join("note.txt"); File::create_new(&p).unwrap(); let e = fs::read_dir("bm-fixture").unwrap().next().unwrap().unwrap(); println!("{} {}", e.file_name().to_str().unwrap(), e.file_type().unwrap().is_file());}