#filename #name #find-files #up #search #tree #lookup

file_lookup

Simple functions to search up in the file tree for a file by name

2 releases

0.2.2 Oct 17, 2023
0.2.1 Jun 19, 2023
0.2.0 Apr 24, 2023
0.1.1 Apr 22, 2023
0.1.0 Apr 22, 2023

#533 in Filesystem

30 downloads per month

MIT license

5KB
62 lines

file_lookup

For when you want to look up from the current working directory for a file by name.

Example Usage

Find a file within your home directory, looking up from your current working directory:

use file_lookup::home_find_file;

let path = home_find_file("some_file.json").unwrap();

Find a file within your root directory (or anywhere else), looking up from your current working directory:

use std::path::PathBuf;
use file_lookup::find_file;

let path = find_file("some_file.json", &PathBuf::from("/")).unwrap();

Errors

These functions fail if there is a failure to ascertain your current working directory or your home directory:

pub enum FileLookupError {
    CwdNotFound,
    HomeDirNotFound,
};

Installation

This crate is on crates.io.

Install it with cargo:

$ cargo add file_lookup

Dependencies

~0.1–10MB
~61K SLoC