Struct DirEntry
pub struct DirEntry { /* private fields */ }
A directory entry.
This is the type of value that is yielded from the iterators defined in this crate.
On Unix systems, this type implements the DirEntryExt trait, which
provides efficient access to the inode number of the directory entry.
Differences with std::fs::DirEntry
This type mostly mirrors the type by the same name in std::fs. There
are some differences however:
- All recursive directory iterators must inspect the entry's type. Therefore, the value is stored and its access is guaranteed to be cheap and successful.
pathandfile_namereturn borrowed variants.- If
follow_linkswas enabled on the originating iterator, then all operations except forpathoperate on the link target. Otherwise, all operations operate on the symbolic link.
Implementations
impl DirEntry
fn path(&self) -> &PathThe full path that this entry represents.
The full path is created by joining the parents of this entry up to the root initially given to
WalkDir::newwith the file name of this entry.Note that this always returns the path reported by the underlying directory entry, even when symbolic links are followed. To get the target path, use
path_is_symlinkto (cheaply) check if this entry corresponds to a symbolic link, andstd::fs::read_linkto resolve the target.fn into_path(self) -> PathBufThe full path that this entry represents.
Analogous to
path, but moves ownership of the path.fn path_is_symlink(&self) -> boolReturns
trueif and only if this entry was created from a symbolic link. This is unaffected by thefollow_linkssetting.When
true, the value returned by thepathmethod is a symbolic link name. To get the full target path, you must callstd::fs::read_link(entry.path()).fn metadata(&self) -> Result<Metadata>Return the metadata for the file that this entry points to.
This will follow symbolic links if and only if the
WalkDirvalue hasfollow_linksenabled.Platform behavior
This always calls
std::fs::symlink_metadata.If this entry is a symbolic link and
follow_linksis enabled, thenstd::fs::metadatais called instead.Errors
Similar to
std::fs::metadata, returns errors for path values that the program does not have permissions to access or if the path does not exist.fn file_type(&self) -> FileTypeReturn the file type for the file that this entry points to.
If this is a symbolic link and
follow_linksistrue, then this returns the type of the target.This never makes any system calls.
fn file_name(&self) -> &OsStrReturn the file name of this entry.
If this entry has no file name (e.g.,
/), then the full path is returned.fn depth(&self) -> usizeReturns the depth at which this entry was created relative to the root.
The smallest depth is
0and always corresponds to the path given to thenewfunction onWalkDir. Its direct descendents have depth1, and their descendents have depth2, and so on.
Trait Implementations
impl Clone for DirEntry
fn clone(&self) -> DirEntry
impl Debug for DirEntry
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl DirEntryExt for DirEntry
fn ino(&self) -> u64Returns the underlying
d_inofield in the containeddirentstructure.
Auto Trait Implementations
impl Freeze for DirEntry
impl RefUnwindSafe for DirEntry
impl Send for DirEntry
impl Sync for DirEntry
impl Unpin for DirEntry
impl UnsafeUnpin for DirEntry
impl UnwindSafe for DirEntry
Blanket Implementations
impl<T> Any for DirEntry
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for DirEntry
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for DirEntry
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for DirEntry
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for DirEntry
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for DirEntry
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for DirEntry
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for DirEntry
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for DirEntry
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>