pub struct DirEntry { /* private fields */ }
Expand description
An entry returned by the ReadDir
iterator.
A DirEntry
represents an item within a directory on the Brain’s Micro SD card.
The Brain provides very little metadata on files, so only the base std DirEntry
methods are supported.
Implementations§
Source§impl DirEntry
impl DirEntry
Sourcepub fn path(&self) -> PathBuf
pub fn path(&self) -> PathBuf
Returns the full path to the directory item.
This path is creeated by joining the path of the call to read_dir
to the name of the file.
§Examples
for entry in fs::read_dir(".").unwrap() {
println!("{:?}", entry.path());
}
This example will lead to output like:
"somefile.txt"
"breakingbadseason1.mp4"
"badapple.mp3"
Sourcepub fn metadata(&self) -> Result<Metadata>
pub fn metadata(&self) -> Result<Metadata>
Returns the metadata for the full path to the item.
This is equivalent to calling metadata
with the output from DirEntry::path
.
§Errors
This function will error if the path does not exist.
§Examples
for entry in read_dir("somepath") {
println!(
"{:?} is a {}.",
entry.path(),
match entry.metadata().is_file() {
true => "file",
false => "folder"
}
);
}
Sourcepub fn file_type(&self) -> Result<FileType>
pub fn file_type(&self) -> Result<FileType>
Returns the file type of the file that this DirEntry
points to.
This function is equivalent to getting the FileType
from the metadata returned by DirEntry::metadata
.
§Errors
This function will error if the path does not exist.
§Examples
for entry in read_dir("somepath") {
println!(
"{:?} is a {}.",
entry.path(),
match entry.file_type().is_file() {
true => "file",
false => "folder"
}
);
}