Skip to content

A library for finding the first matching item in a directory.

License

Notifications You must be signed in to change notification settings

NatanFreeman/search_dir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust

search_dir

A Rust library for finding the first matching item in a directory.

Usage

Add the following to your Cargo.toml:

[dependencies]
search_dir = "0.1.2"

Example

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(&current_dir, "hello.txt", ItemType::File)?;

   println!("{:?}", found_path);
   current_dir.push("some");
   fs::remove_dir_all(current_dir)?;
   Ok(())
}

License

This project is licensed under Apache License, Version 2.0

About

A library for finding the first matching item in a directory.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages