file-crawler

Crates.iofile-crawler
lib.rsfile-crawler
version0.1.5
created_at2025-09-09 15:02:13.420039+00
updated_at2025-10-05 20:01:35.435851+00
descriptionA fast, concurrent, async and customisable file crawler
homepage
repositoryhttps://github.com/HQ2000-Rust/Custom-File-Crawler
max_upload_size
id1831020
size49,336
Jonathan Schmittat (HQ2000-Rust)

documentation

README

A fast, concurrent, customisable, optionally async and fully documented file crawler!

Features:

  • fully multithreaded by default (more than 2 times faster, depending)
  • Two options:
    • async
    • non-async
  • set maximum traversal depth
  • set file / folder regex
  • lazyness (see lazy evaluation)
  • execution a closure for every file (in the defined scope)
  • having persistent data across closure invocations
  • (set start directory)

Example usage

fn main() -> Box<dyn Error> {
    use file_crawler::prelude::*;

    use std::fs::File;
    use std::path::PathBuf;
    use std::sync::Arc;
    use std::sync::atomic::AtomicU32;

    let a_count =
        Crawler::new()
            .start_dir("C\\user\\foo")
            .context(AtomicU32::new(0))
            .run(|ctx: Arc<AtomicU32>, path: PathBuf| {
                let mut contents = String::new();
                let file = File::open(path)?;
                //NOTE: this can cause an error for files not readable as UTF-8
                //which returns an error and therefore terminates the crawler
                file.read_to_string(&mut contents)?;
                contents.chars().for_each(|char| if char == 'a' { ctx.fetch_add(1); });
                Ok(())
            })?;
    println!("Appearance of the letter 'a' in \"C\\user\\foo\": {}", a_count);
}
Commit count: 46

cargo fmt