Skip to content

ityuany/up_finder

Repository files navigation

up_finder

Crates.io Documentation License: MIT

A lightweight Rust library for finding files or directories upward in the directory tree.

English | 中文

Features

  • Find files or directories in the current working directory and all parent directories
  • Support for finding a single file or multiple files
  • High-performance HashMap implementation using rustc-hash
  • Concise builder API implemented with typed-builder
  • No external system dependencies, pure Rust implementation

Installation

Add the following dependency to your Cargo.toml file:

[dependencies]
up_finder = "0.0.2"

Usage Examples

Find a Single File

use up_finder::{UpFinder, FindUpKind};

// Create a UpFinder instance, default is to find files
let find_up = UpFinder::builder()
    .cwd(".")  // Start from the current directory
    .kind(FindUpKind::File)  // Optional, finding files is the default
    .build();

// Find package.json files upward
let paths = find_up.find_up("package.json");

// Print all found paths
println!("{:#?}", paths);

Find Multiple Files

use up_finder::{UpFinder, FindUpKind};

// Create a UpFinder instance
let find_up = UpFinder::builder()
    .cwd("./src")  // Start from the src directory
    .build();

// Find multiple files simultaneously
let paths = find_up.find_up_multi(&["package.json", ".gitignore", "Cargo.toml"]);

// Result is a HashMap with file names as keys and lists of found paths as values
for (file_name, file_paths) in paths {
    println!("Found {} {} files:", file_paths.len(), file_name);
    for path in file_paths {
        println!("  - {}", path.display());
    }
}

Find Directories

use up_finder::{UpFinder, FindUpKind};

// Create a UpFinder instance for finding directories
let find_up = UpFinder::builder()
    .cwd(".")
    .kind(FindUpKind::Dir)  // Set to find directories
    .build();

// Find "node_modules" directories upward
let paths = find_up.find_up("node_modules");

println!("{:#?}", paths);

API Documentation

For detailed API documentation, visit docs.rs/up_finder.

Contribution

Issues and pull requests are welcome!

License

This project is licensed under the MIT License.

About

Find files or directories upward in the directory tree.

Resources

License

Stars

Watchers

Forks

Packages

No packages published