pub struct DirEntry {/* private fields */ }
Expand description
A directory entry.
This is the type of value that is yielded from the iterators defined inthis crate.
On Unix systems, this type implements theDirEntryExt
trait, whichprovides efficient access to the inode number of the directory entry.
§Differences withstd::fs::DirEntry
This type mostly mirrors the type by the same name instd::fs
. Thereare 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 andsuccessful.
path
andfile_name
return borrowed variants.- If
follow_links
was enabled on the originating iterator, then alloperations except forpath
operate on the link target. Otherwise, alloperations operate on the symbolic link.
Implementations§
Source§implDirEntry
implDirEntry
Sourcepub fnpath(&self) -> &Path
pub fnpath(&self) -> &Path
The full path that this entry represents.
The full path is created by joining the parents of this entry up to theroot initially given toWalkDir::new
with the file name of thisentry.
Note that thisalways returns the path reported by the underlyingdirectory entry, even when symbolic links are followed. To get thetarget path, usepath_is_symlink
to (cheaply) check if this entrycorresponds to a symbolic link, andstd::fs::read_link
to resolvethe target.
Sourcepub fninto_path(self) ->PathBuf
pub fninto_path(self) ->PathBuf
The full path that this entry represents.
Analogous topath
, but moves ownership of the path.
Sourcepub fnpath_is_symlink(&self) ->bool
pub fnpath_is_symlink(&self) ->bool
Returnstrue
if and only if this entry was created from a symboliclink. This is unaffected by thefollow_links
setting.
Whentrue
, the value returned by thepath
method is asymbolic link name. To get the full target path, you must callstd::fs::read_link(entry.path())
.
Sourcepub fnmetadata(&self) ->Result<Metadata>
pub fnmetadata(&self) ->Result<Metadata>
Return the metadata for the file that this entry points to.
This will follow symbolic links if and only if theWalkDir
valuehasfollow_links
enabled.
§Platform behavior
This always callsstd::fs::symlink_metadata
.
If this entry is a symbolic link andfollow_links
is enabled, thenstd::fs::metadata
is called instead.
§Errors
Similar tostd::fs::metadata
, returns errors for path values thatthe program does not have permissions to access or if the path does notexist.
Sourcepub fnfile_type(&self) ->FileType
pub fnfile_type(&self) ->FileType
Return the file type for the file that this entry points to.
If this is a symbolic link andfollow_links
istrue
, then thisreturns the type of the target.
This never makes any system calls.