4 个版本
0.1.3 | 2022年7月6日 |
---|---|
0.1.2 | 2022年6月30日 |
0.1.1 | 2022年6月19日 |
0.1.0 | 2022年6月19日 |
#1705 in 文件系统
16KB
231 代码行
search_dir
用于在目录中查找第一个匹配项的Rust库。
用法
将以下内容添加到您的 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(())
}
许可证
本项目采用 Apache许可证,版本2.0 许可。
依赖项
~5–15MB
~190K SLoC