Haskell中有一些目录漫游者吗? [英] Is there some directory walker in Haskell?
本文介绍了Haskell中有一些目录漫游者吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Haskell中是否有一些递归目录漫游器,所以我可以编写类似
Is there some recursive directory walker in Haskell so I could write something like
listing <- walkDir "/tmp"
我不想自己写。我可以从cabal安装一些依赖,但我希望它是跨平台的(至少是Linux和Windows)。
I would not like to write my own. I can install some dependency from cabal but I want it to be cross platform (at least Linux and Windows).
推荐答案
这是使用目录树列出目录树中所有Haskell文件的一种方法隐藏目录(名称以'。'开头):
Here is one way to list all Haskell files in a directory tree, using directory-tree that is not in a hidden directory (whose name starts with '.'):
import Data.Traversable (traverse)
import System.Directory.Tree (
AnchoredDirTree(..), DirTree(..),
filterDir, readDirectoryWith
)
import System.FilePath (takeExtension)
listFilesDirFiltered = do
_:/tree <- readDirectoryWith return "C:\\devmy\\code"
traverse print $ filterDir myPred tree
return ()
where myPred (Dir ('.':_) _) = False
myPred (File n _) = takeExtension n == ".hs"
myPred _ = True
main = listFilesDirFiltered
适用于Windows和Linux。
Works on both Windows and Linux.
这篇关于Haskell中有一些目录漫游者吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文