#file-path #unix-file #file-search #recursion #symlink #directory #finding

dowser

A recursive, canonicalizing file finding library for Unix

41 releases

0.11.0 Dec 10, 2024
0.10.1 Nov 28, 2024
0.10.0 Oct 23, 2024
0.9.2 Jul 25, 2024
0.2.0 Mar 7, 2021

#405 in Filesystem

Download history 28/week @ 2024-09-13 86/week @ 2024-09-20 50/week @ 2024-09-27 7/week @ 2024-10-04 8/week @ 2024-10-11 161/week @ 2024-10-18 26/week @ 2024-10-25 19/week @ 2024-11-01 9/week @ 2024-11-08 1/week @ 2024-11-15 82/week @ 2024-11-22 88/week @ 2024-11-29 144/week @ 2024-12-06 27/week @ 2024-12-13

173 downloads per month

WTFPL license

51KB
687 lines

Dowser

docs.rs changelog
crates.io ci deps.rs
license contributions welcome

Dowser is a(nother) fast, recursive file-finding library for Unix/Rust. It differs from Walkdir and kin in a number of ways:

  • It is not limited to one root; any number of file and directory paths can be loaded and traversed en masse;
  • Symlinks and hidden directories are followed like any other, including across devices;
  • Matching file paths are canonicalized and deduped before yielding;

If those things sound nice, this library might be a good fit.

On the other hand, Dowser is optimized for file searching; the iterator crawls but does not yield directory paths, which could be bad if you need those too. Haha.

Installation

Add dowser to your dependencies in Cargo.toml, like:

[dependencies]
dowser = "0.11.*"

Example

All you need to do is chain Dowser::default with one or more of the following seed methods:

  • Dowser::with_path / Dowser::with_paths
  • Dowser::without_path / Dowser::without_paths

From there, you can apply any Iterator methods you want, or immediately collect the results using Dowser::into_vec or Dowser::into_vec_filtered.

use dowser::Dowser;
use std::path::PathBuf;

// Return all files under "/usr/share/man".
let files1: Vec::<PathBuf> = Dowser::default()
    .with_path("/usr/share/man")
    .collect();

// Same as above, but slightly faster.
let files2: Vec::<PathBuf> = Dowser::default()
    .with_path("/usr/share/man")
    .into_vec();

assert_eq!(files1.len(), files2.len());

// Return only Gzipped files using callback filter.
let files1: Vec::<PathBuf> = Dowser::default()
    .with_path("/usr/share/man")
    .filter(|p|
        p.extension().is_some_and(|e| e.eq_ignore_ascii_case("gz"))
    )
    .collect();

// Same as above, but slightly faster.
let files2: Vec::<PathBuf> = Dowser::default()
    .with_path("/usr/share/man")
    .into_vec_filtered(|p|
        p.extension().is_some_and(|e| e.eq_ignore_ascii_case("gz"))
    );

assert_eq!(files1.len(), files2.len());

Dependencies

~1MB
~18K SLoC