gpt4 book ai didi

WalkDir skip all subdirectories if the parent name is X(如果父目录名称为X,则WalkDir跳过所有子目录)

转载 作者:bug小助手 更新时间:2023-10-28 09:33:54 26 4
gpt4 key购买 nike



I want to print all the subdirectories in the current directory, however if the directory is called node_modules

我想打印当前目录中的所有子目录,但是如果该目录名为node_MODULES


I don't want to go inside of it to check for more subdirectories.

我不想进入它的内部来检查更多的子目录。


This is my current code:

这是我当前的代码:


use walkdir::{DirEntry, WalkDir};

fn is_dir(entry: &DirEntry) -> bool {
entry.metadata().unwrap().is_dir()
}

fn main() {
WalkDir::new(".")
.into_iter()
.filter_entry(|e| is_dir(e))
.filter_map(|v| v.ok())
.for_each(|x| println!("{}", x.path().display()));
}

I have seen the skip_current_dir function on the documentation, however I was wondering if there is any way to call it from the filter itself instead of having to create a loop to look at the operator.

我在文档中看到了Skip_Current_dir函数,但是我想知道是否有任何方法可以从过滤器本身调用它,而不是必须创建一个循环来查看操作符。


更多回答

Why not just filter out node_modules?

为什么不直接过滤掉NODE_MODULES呢?

I don't want to filter node_modules out, I want to ignore all the files/folders inside a node_modules folder.

我并不想过滤出NODE_MODULES,我想忽略NODE_MODULES文件夹中的所有文件/文件夹。

优秀答案推荐
更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com