避免使用filemanip递归到specifc文件夹 [英] avoid recursion into specifc folder using filemanip
问题描述
我正在探索 filemanip 库,以在包含子文件夹的路径中搜索降价文件 >
I am exploring the filemanip library to search for markdown files in a path including subfolders
import System.FilePath.Find
find always (fileType ==? RegularFile &&? extension ==? ".md") "a/path/"
有什么方法可以指定不应递归的文件夹名称或模式
is there any way to specify a folder name or pattern into which it should not recurse
推荐答案
通过查看文档,我们可以看到 RecursionPredicate 依次为
Looking at the documentation we can see that find takes as first argument a RecursionPredicate which in turn is just FindClause Bool
.
基于此,我们可以看到我们必须将自定义RecursionPredicate
传递给除always
之外的find
.
一个示例是忽略.git
目录:
Based on this we can see that we have to pass in a custom RecursionPredicate
to find
other than always
.
One example is to ignore .git
directories:
notGit :: FindClause Bool -- or via type alias also a RecursionPredicate
notGit = directory /=? ".git"
然后我们将新的递归谓词与find
一起使用:
We then just use our new recursion predicate with find
:
find notGit (fileType ==? RegularFile &&? extension ==? ".md") path
Note also the special combinators for predicates to e.g. compose a notSvn
predicate with our notGit
predicate via (||?)
to get a predicate that enters neither directories.
这篇关于避免使用filemanip递归到specifc文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!