pub struct DirMetadata<'a> { /* private fields */ }Expand description
The Metadata of all directories and files in the current directory
§Example
use dir_meta::DirMetadata;
// With feature `async` enabled using `cargo add dir-meta --features async`
#[cfg(feature = "async")]
{
let dir = DirMetadata::new("/path/to/directory").async_dir_metadata();
}
// With feature `sync` enabled using `cargo add dir-meta --features sync`
#[cfg(feature = "sync")]
{
let dir = DirMetadata::new("/path/to/directory").sync_dir_metadata();
}Implementations§
Source§impl<'a> DirMetadata<'_>
impl<'a> DirMetadata<'_>
Sourcepub fn new_path_buf(path: PathBuf) -> Self
pub fn new_path_buf(path: PathBuf) -> Self
Create a new instance of Self
Sourcepub fn get_file(&self, file_name: &'a str) -> Vec<&'a FileMetadata<'_>>
pub fn get_file(&self, file_name: &'a str) -> Vec<&'a FileMetadata<'_>>
Multiple files can have the same name if they are in different dirs so using this method returns a vector of FileMetadata
Sourcepub fn get_file_by_path(&self, path: &'a str) -> Option<&'a FileMetadata<'_>>
pub fn get_file_by_path(&self, path: &'a str) -> Option<&'a FileMetadata<'_>>
Get a file by it’s absolute path (from root)
Sourcepub async fn async_dir_metadata(self) -> Result<Self, Error>
pub async fn async_dir_metadata(self) -> Result<Self, Error>
Returns an error if the directory cannot be accessed Read all the directories and files in the given path in async fashion
Sourcepub fn sync_dir_metadata(self) -> Result<Self, Error>
pub fn sync_dir_metadata(self) -> Result<Self, Error>
Returns an error if the directory cannot be accessed Read all the directories and files in the given path
Sourcepub fn async_iter_dir<'life0, 'async_recursion>(
&'a mut self,
prepared_dir: &'life0 mut ReadDir,
) -> Pin<Box<dyn Future<Output = &'a mut Self> + Send + 'async_recursion>>where
'life0: 'async_recursion,
'a: 'async_recursion,
pub fn async_iter_dir<'life0, 'async_recursion>(
&'a mut self,
prepared_dir: &'life0 mut ReadDir,
) -> Pin<Box<dyn Future<Output = &'a mut Self> + Send + 'async_recursion>>where
'life0: 'async_recursion,
'a: 'async_recursion,
Recursively iterate over directories inside directories
Sourcepub fn sync_iter_dir(&mut self, prepared_dir: &mut ReadDir) -> &mut Self
pub fn sync_iter_dir(&mut self, prepared_dir: &mut ReadDir) -> &mut Self
Recursively iterate over directories inside directories
Sourcepub fn directories(&self) -> &[PathBuf]
pub fn directories(&self) -> &[PathBuf]
Get all the sub-directories of the current directory
Sourcepub fn files(&'a self) -> &'a [FileMetadata<'a>]
pub fn files(&'a self) -> &'a [FileMetadata<'a>]
Get all the files in the current directory and all the files in it’s sub-directory
Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Get the size of the directory including the size of all files in the sub-directories
Sourcepub fn size_formatted(&self) -> String
pub fn size_formatted(&self) -> String
Get the size of the directory including the size of all files in the sub-directories in human readable format
Trait Implementations§
Source§impl<'a> Clone for DirMetadata<'a>
impl<'a> Clone for DirMetadata<'a>
Source§fn clone(&self) -> DirMetadata<'a>
fn clone(&self) -> DirMetadata<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more