Struct walkdir::DirEntry

source ·
pub struct DirEntry { /* private fields */ }
Expand description

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.
  • path and file_name return borrowed variants.
  • If follow_links was enabled on the originating iterator, then all operations except for path operate on the link target. Otherwise, all operations operate on the symbolic link.

Implementations§

source§

impl DirEntry

source

pub fn path(&self) -> &Path

The 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::new with 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_symlink to (cheaply) check if this entry corresponds to a symbolic link, and std::fs::read_link to resolve the target.

source

pub fn into_path(self) -> PathBuf

The full path that this entry represents.

Analogous to path, but moves ownership of the path.

Returns true if and only if this entry was created from a symbolic link. This is unaffected by the follow_links setting.

When true, the value returned by the path method is a symbolic link name. To get the full target path, you must call std::fs::read_link(entry.path()).

source

pub 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 WalkDir value has follow_links enabled.

§Platform behavior

This always calls std::fs::symlink_metadata.

If this entry is a symbolic link and follow_links is enabled, then std::fs::metadata is 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.

source

pub fn file_type(&self) -> FileType

Return the file type for the file that this entry points to.

If this is a symbolic link and follow_links is true, then this returns the type of the target.

This never makes any system calls.

source

pub fn file_name(&self) -> &OsStr

Return the file name of this entry.

If this entry has no file name (e.g., /), then the full path is returned.

source

pub fn depth(&self) -> usize

Returns the depth at which this entry was created relative to the root.

The smallest depth is 0 and always corresponds to the path given to the new function on WalkDir. Its direct descendents have depth 1, and their descendents have depth 2, and so on.

Trait Implementations§

source§

impl Clone for DirEntry

source§

fn clone(&self) -> DirEntry

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for DirEntry

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl DirEntryExt for DirEntry

source§

fn ino(&self) -> u64

Returns the underlying d_ino field in the contained dirent structure.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.