Crates.io | search_dir |
lib.rs | search_dir |
version | 0.1.3 |
source | src |
created_at | 2022-06-19 15:26:15.608794 |
updated_at | 2022-07-06 17:41:27.985788 |
description | A Rust library for finding the first matching item in a directory. |
homepage | |
repository | https://github.com/NatanFreeman/search_dir |
max_upload_size | |
id | 608988 |
size | 29,209 |
A Rust library for finding the first matching item in a directory.
Add the following to your Cargo.toml
:
[dependencies]
search_dir = "0.1.2"
use std::fs;
use std::env;
use std::error::Error;
use search_dir::search::{ItemType, find_item};
fn main()->Result<(), Box<dyn Error>> {
//creates directory we want to search
fs::create_dir_all("./some/awesome/really/cool/")?;
fs::write("./some/awesome/really/cool/hello.txt", "this is a file")?;
let mut current_dir = env::current_dir()?;
//searches for a file called `hello.txt`
let found_path = find_item(¤t_dir, "hello.txt", ItemType::File)?;
println!("{:?}", found_path);
current_dir.push("some");
fs::remove_dir_all(current_dir)?;
Ok(())
}
This project is licensed under Apache License, Version 2.0