walkfile

Crates.iowalkfile
lib.rswalkfile
version0.1.0
sourcesrc
created_at2024-06-08 16:51:54.828364
updated_at2024-06-08 16:51:54.828364
description遍历指定目录下的所有文件夹,文件
homepage
repositoryhttps://github.com/liuhuo23/app.git
max_upload_size
id1265836
size6,602
(liuhuo23)

documentation

README

walkfile

Struct walkfile::WalkFileEntry

pub struct WalkFileEntry {
    pub root: PathBuf,
    pub child_dirs: Vec<String>,
    pub child_files: Vec<String>,
}

WalfFileENtry

  • root: 根目录
  • child_dirs: root下所有的子文件夹名称
  • child_files: root下所有的文件

Function walkfile::walkCopy

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",
        ],
    },
]
Commit count: 14

cargo fmt