Crate lrg

Source
Expand description

lrg is a library for find the largest (or smallest) files in a given directory. There is also support for searching by a custom function, given DirEntry’s. In addition to this, you can specify (in LrgOptions) the minimum depth and maximum depth to search for, such as if you wanted to prevent recursion. You can also speficy whether to follow links or to include directories.

Note: DirEntry is a typedef of walkdir::DirEntry

§Examples

To find the largest files in a directory:

use std::path::Path;
use lrg::{Lrg, LrgOptions, DirEntry, SortBy};
// Get a path to some directory (or file)
let path = Path::new("./some/path");
// Create the Lrg object to store the entries
let mut lrg: Lrg = Lrg::new(path, &LrgOptions::default());
// Sort and get the entries
let mut entries: Vec<DirEntry> = lrg.sort_by(&SortBy::Descending).get_entries();
// You can also call `sort_descending`
entries = lrg.sort_descending().get_entries();
// These calls mutate the underlying struct, so calling:
entries = lrg.get_entries();
// Will give you the same as the call before it

To find the smallest files in a directory:

let path = Path::new("./some/other/path");
let mut lrg: Lrg = Lrg::new(path, &LrgOptions::default());
let entries: Vec<DirEntry> = lrg.sort_ascending().get_entries();

To search using a custom function:

let path = Path::new("./another/path");
let mut lrg: Lrg = Lrg::new(path, &LrgOptions::default());
// Sort by filename (note: not the full path)
lrg.sort_by_custom(|a: &DirEntry, b: &DirEntry| {
    a.file_name().cmp(b.file_name())
});
let entries: Vec<DirEntry> = lrg.get_entries();

Structs§

Lrg
The main struct for searching for files by size. Constructed using new, passing in a path and options.
LrgOptions
Options when constructing an Lrg struct.

Enums§

SortBy
Specifies the sorting algorithm.

Functions§

get_walkdir_error_str
This function gets a string for a walkdir error. This is needed since io_error.to_str() is not public.

Type Aliases§

DirEntry
A type copy of the walkdir::DirEntry struct.