walkfile 0.1.0

遍历指定目录下的所有文件夹,文件
Documentation
  • Coverage
  • 50%
    4 out of 8 items documented3 out of 4 items with examples
  • Size
  • Source code size: 6.5 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 392.61 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • liuhuo23

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",
        ],
    },
]