Struct DirEntry
struct DirEntry { ... }
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: &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: Self) -> PathBufThe full path that this entry represents.
Analogous to
path, but moves ownership of the path.fn path_is_symlink(self: &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: &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: &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: &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: &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.
impl Clone for DirEntry
fn clone(self: &Self) -> DirEntry
impl Debug for DirEntry
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl DirEntryExt for DirEntry
fn ino(self: &Self) -> u64Returns the underlying
d_inofield in the containeddirentstructure.
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
impl<T> Any for DirEntry
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for DirEntry
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for DirEntry
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for DirEntry
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for DirEntry
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for DirEntry
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for DirEntry
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for DirEntry
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for DirEntry
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>