1 个不稳定版本
| 0.1.0 | 2024 年 3 月 23 日 |
|---|
#913 在 文件系统
15KB
206 行
dirscent — 目录递归
dirscent 提供了一个简单高效的迭代器,用于遍历目录条目,并递归遍历所有子目录的条目。
安装
将依赖项添加到您的 Cargo.toml
[dependencies]
dirscent = "0.1"
或者从命令行
% cargo add dirscent@0.1
用法
遍历层次结构,跳过进程没有权限的条目
use dirscent::dirscent;
fn main() {
for it in dirscent("/usr")
.unwrap()
.postorder()
.skip_permission_denied()
{
match it {
Ok(entry) => println!("{}", entry.path().display()),
Err(err) => eprintln!("{err:?}"),
}
}
}
性能
在我的系统上,dirscent 比 fts(3) 快 1.5 倍,比 find(1) 快 2 倍。运行 benches/b.sh 看看效果。