Crates.io | walkfile |
lib.rs | walkfile |
version | 0.1.0 |
source | src |
created_at | 2024-06-08 16:51:54.828364 |
updated_at | 2024-06-08 16:51:54.828364 |
description | 遍历指定目录下的所有文件夹,文件 |
homepage | |
repository | https://github.com/liuhuo23/app.git |
max_upload_size | |
id | 1265836 |
size | 6,602 |
pub struct WalkFileEntry {
pub root: PathBuf,
pub child_dirs: Vec<String>,
pub child_files: Vec<String>,
}
pub fn walk(path: &PathBuf) -> Result<Vec<WalkFileEntry>>
遍历指定根目录的入口函数
use std::{path::PathBuf, str::FromStr};
use crate::walk;
use anyhow::{Ok, Result};
fn test_walk(){
let res = walk(&PathBuf::from_str("./").unwrap());
let res = match res {
Err(e) => panic!("{}", e),
Ok(res) => res
};
print!("{}", res[1]);
}
cargo.toml
[dependencies]
walkfile = "*"
fn test_ref_tuple(){
let res = walk(&PathBuf::from_str("./").unwrap());
let res = match res {
Err(e) => panic!("{}", e),
Ok(res) => res
};
let (root, child_dirs, child_files) = res[0].as_tuple();
println!("{:?}, {:?}, {:?}", root, child_dirs, child_files);
}
[
WalkFileEntry {
root: "./src",
child_dirs: [],
child_files: [
"lib.rs",
],
},
WalkFileEntry {
root: "./",
child_dirs: [
"src",
],
child_files: [
"Cargo.toml",
"readme.md",
],
},
]