pub struct Lrg { /* private fields */ }
Expand description
The main struct for searching for files by size.
Constructed using new
, passing in a path and options.
Implementations§
source§impl Lrg
impl Lrg
sourcepub fn new(path: &Path, options: &LrgOptions) -> Self
pub fn new(path: &Path, options: &LrgOptions) -> Self
Creates a new Lrg with options and at the given path.
Examples
let path = Path::new(".");
let lrg = Lrg::new(path, &LrgOptions::default());
To use custom options, just supply a LrgOptions
struct.
To only search the base directoy, using the other default options:
let path = Path::new(".");
let opts = LrgOptions {
min_depth: 1,
..LrgOptions::default()
};
sourcepub fn sort_by(&mut self, cmp: &SortBy) -> &Self
pub fn sort_by(&mut self, cmp: &SortBy) -> &Self
Sorts the lrg object entries, and returns the lrg object.
Examples
To get the largest files first:
let path = Path::new(".");
let mut lrg = Lrg::new(path, &LrgOptions::default());
lrg.sort_by(&SortBy::Descending);
sourcepub fn sort_by_custom<F>(&mut self, cmp: F) -> &Selfwhere
F: FnMut(&DirEntry, &DirEntry) -> Ordering,
pub fn sort_by_custom<F>(&mut self, cmp: F) -> &Selfwhere
F: FnMut(&DirEntry, &DirEntry) -> Ordering,
Sorts the lrg object entries by a custom sort function, and returns the lrg object.
Examples
To search by creation date:
let path = Path::new("./another/path");
let mut lrg = Lrg::new(path, &LrgOptions::default());
lrg.sort_by_custom(|a: &DirEntry, b: &DirEntry| {
// Create custom function to get creation date of a `DirEntry`
let creation_date = |x: &DirEntry| {
match x.metadata() {
Ok(meta) => {
match meta.created() {
Ok(created) => created,
Err(_) => std::time::SystemTime::UNIX_EPOCH,
}
},
// Default to UNIX epoch
Err(_) => std::time::SystemTime::UNIX_EPOCH,
}
};
//Make comparison
creation_date(a).cmp(&creation_date(b))
});
// Get entries
let entries: Vec<DirEntry> = lrg.get_entries();
sourcepub fn sort_ascending(&mut self) -> &Self
pub fn sort_ascending(&mut self) -> &Self
Sorts the lrg object entries by ascending file size, and returns the lrg object.
Examples
let path = Path::new("./another/path");
let mut lrg: Lrg = Lrg::new(path, &LrgOptions::default());
let entries = lrg.sort_ascending().get_entries();
sourcepub fn sort_descending(&mut self) -> &Self
pub fn sort_descending(&mut self) -> &Self
Sorts the lrg object entries by descending file size, and returns the lrg object.
Examples
let path = Path::new("./another/path");
let mut lrg: Lrg = Lrg::new(path, &LrgOptions::default());
let entries = lrg.sort_descending().get_entries();